Re-use old hashes to speed up build_manifest
This commit is contained in:
@@ -43,14 +43,14 @@ class ManifestBuilder(object):
|
|||||||
self._image_dir = image_dir
|
self._image_dir = image_dir
|
||||||
self._old_manifest = old_manifest
|
self._old_manifest = old_manifest
|
||||||
|
|
||||||
def _Rollouts(self):
|
def _OldImages(self):
|
||||||
if not self._old_manifest:
|
if not self._old_manifest:
|
||||||
return {}
|
return {}
|
||||||
try:
|
try:
|
||||||
with open(self._old_manifest, 'r') as fh:
|
with open(self._old_manifest, 'r') as fh:
|
||||||
parsed = json.load(fh)
|
parsed = json.load(fh)
|
||||||
return dict(
|
return dict(
|
||||||
(image['timestamp'], image['rollout_‱'])
|
(image['timestamp'], image)
|
||||||
for image in parsed['images'])
|
for image in parsed['images'])
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return {}
|
return {}
|
||||||
@@ -60,7 +60,7 @@ class ManifestBuilder(object):
|
|||||||
'timestamp': int(time.time()),
|
'timestamp': int(time.time()),
|
||||||
'images': [],
|
'images': [],
|
||||||
}
|
}
|
||||||
rollouts = self._Rollouts()
|
old_images = self._OldImages()
|
||||||
for filename in os.listdir(self._image_dir):
|
for filename in os.listdir(self._image_dir):
|
||||||
match = self._FILE_REGEX.match(filename)
|
match = self._FILE_REGEX.match(filename)
|
||||||
if not match:
|
if not match:
|
||||||
@@ -68,8 +68,15 @@ class ManifestBuilder(object):
|
|||||||
timestamp = int(match.group('timestamp'))
|
timestamp = int(match.group('timestamp'))
|
||||||
image = {
|
image = {
|
||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'rollout_‱': rollouts.get(timestamp, FLAGS.default_rollout),
|
'rollout_‱': FLAGS.default_rollout,
|
||||||
}
|
}
|
||||||
|
ret['images'].append(image)
|
||||||
|
|
||||||
|
old_image = old_images.get(timestamp)
|
||||||
|
if old_image:
|
||||||
|
image.update(old_image)
|
||||||
|
continue
|
||||||
|
|
||||||
with open(os.path.join(self._image_dir, filename), 'rb') as fh:
|
with open(os.path.join(self._image_dir, filename), 'rb') as fh:
|
||||||
hash_obj = hashlib.sha256()
|
hash_obj = hashlib.sha256()
|
||||||
while True:
|
while True:
|
||||||
@@ -78,7 +85,7 @@ class ManifestBuilder(object):
|
|||||||
break
|
break
|
||||||
hash_obj.update(data)
|
hash_obj.update(data)
|
||||||
image['hash'] = hash_obj.hexdigest()
|
image['hash'] = hash_obj.hexdigest()
|
||||||
ret['images'].append(image)
|
|
||||||
ret['images'].sort(key=lambda x: x['timestamp'], reverse=True)
|
ret['images'].sort(key=lambda x: x['timestamp'], reverse=True)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user