0

Check if the key exists first

This commit is contained in:
Ryan McCue
2010-12-13 21:21:24 +10:00
parent 8def0ffaef
commit fcfaffffbb
2 changed files with 2 additions and 12 deletions

View File

@@ -330,16 +330,6 @@ class ChunkRenderer(object):
""" """
blockid = self.blockid blockid = self.blockid
if self.oldimg:
# An image exists? Instead of checking the hash which is kinda
# expensive (for tens of thousands of chunks, yes it is) check if
# the mtime of the chunk file is newer than the mtime of oldimg
if os.path.getmtime(self.chunkfile) <= os.path.getmtime(self.oldimg_path):
# chunkfile is older than the image, don't even bother checking
# the hash
logging.debug("Using cached image")
return self.oldimg_path
# Reasons for the code to get to this point: # Reasons for the code to get to this point:
# 1) An old image doesn't exist # 1) An old image doesn't exist
# 2) An old image exists, but the chunk was more recently modified (the # 2) An old image exists, but the chunk was more recently modified (the

View File

@@ -296,7 +296,7 @@ class WorldRenderer(object):
continue continue
oldimg = chunk.find_oldimage(chunkfile, cached, self.caves) oldimg = chunk.find_oldimage(chunkfile, cached, self.caves)
if os.path.getmtime(chunkfile) <= os.path.getmtime(oldimg[1]): if oldimg[1] and (os.path.getmtime(chunkfile) <= os.path.getmtime(oldimg[1])):
result = oldimg[1] result = oldimg[1]
else: else:
result = chunk.render_and_save(chunkfile, self.cachedir, self, oldimg, queue=q) result = chunk.render_and_save(chunkfile, self.cachedir, self, oldimg, queue=q)
@@ -327,7 +327,7 @@ class WorldRenderer(object):
continue continue
oldimg = chunk.find_oldimage(chunkfile, cached, self.caves) oldimg = chunk.find_oldimage(chunkfile, cached, self.caves)
if os.path.getmtime(chunkfile) <= os.path.getmtime(oldimg[1]): if oldimg[1] and (os.path.getmtime(chunkfile) <= os.path.getmtime(oldimg[1])):
result = oldimg[1] result = oldimg[1]
else: else:
result = pool.apply_async(chunk.render_and_save, result = pool.apply_async(chunk.render_and_save,