Change ManifestBlob row creation to be a single batch operation

Should reduce DB roundtrip times and the overall time we spend under the transaction
This commit is contained in:
Joseph Schorr 2018-08-09 17:04:16 -04:00
parent 1f04b3ea03
commit 2ab7ca30d0

View file

@ -612,6 +612,7 @@ def _create_manifest(tag, manifest, storage_id_map):
manifest_bytes=manifest.bytes, media_type=media_type)
ManifestLegacyImage.create(manifest=manifest_row, repository=tag.repository, image=tag.image)
blobs_to_insert = []
blobs_created = set()
for blob_digest in reversed(manifest.blob_digests):
image_storage_id = storage_id_map.get(blob_digest)
@ -622,9 +623,13 @@ def _create_manifest(tag, manifest, storage_id_map):
if image_storage_id in blobs_created:
continue
ManifestBlob.create(manifest=manifest_row, repository=tag.repository, blob=image_storage_id)
blobs_to_insert.append(dict(manifest=manifest_row, repository=tag.repository,
blob=image_storage_id))
blobs_created.add(image_storage_id)
if blobs_to_insert:
ManifestBlob.insert_many(blobs_to_insert).execute()
tag_manifest = TagManifest.create(tag=tag, digest=manifest.digest, json_data=manifest.bytes)
TagManifestToManifest.create(tag_manifest=tag_manifest, manifest=manifest_row)
return tag_manifest