Merge pull request #3198 from quay/batch-blob-inserts

Change ManifestBlob row creation to be a single batch operation
This commit is contained in:
Joseph Schorr 2018-08-10 15:11:26 -04:00 committed by GitHub
commit b39f53ee38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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