From 48e469dce29388d67e8027c99be4ca38ec878124 Mon Sep 17 00:00:00 2001 From: Jitka Halova Date: Wed, 3 Jun 2026 16:05:22 +0200 Subject: [PATCH] Optimize QueryExistingArtifacts queries related to #7558 Assisted By: Claude Opus 4.6 (cherry picked from commit 597d7739cb1ba0f42086a6e7b3dfc290405246b3) --- CHANGES/7558.bugfix | 1 + pulpcore/plugin/stages/artifact_stages.py | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 CHANGES/7558.bugfix diff --git a/CHANGES/7558.bugfix b/CHANGES/7558.bugfix new file mode 100644 index 00000000000..6b8310128e0 --- /dev/null +++ b/CHANGES/7558.bugfix @@ -0,0 +1 @@ +Optimized `QueryExistingArtifacts` by reducing database queries. diff --git a/pulpcore/plugin/stages/artifact_stages.py b/pulpcore/plugin/stages/artifact_stages.py index a4431ab455a..0b4ca4e884f 100644 --- a/pulpcore/plugin/stages/artifact_stages.py +++ b/pulpcore/plugin/stages/artifact_stages.py @@ -98,17 +98,15 @@ async def run(self): "pulp_domain": self.domain, } existing_artifacts_qs = Artifact.objects.filter(**query_params) - existing_artifacts = sync_to_async_iterable(existing_artifacts_qs) await sync_to_async(existing_artifacts_qs.touch)() + existing_by_digest = {} + async for result in sync_to_async_iterable(existing_artifacts_qs): + existing_by_digest[getattr(result, digest_type)] = result for d_content in batch: for d_artifact in d_content.d_artifacts: artifact_digest = getattr(d_artifact.artifact, digest_type) - if artifact_digest: - async for result in existing_artifacts: - result_digest = getattr(result, digest_type) - if result_digest == artifact_digest: - d_artifact.artifact = result - break + if artifact_digest and artifact_digest in existing_by_digest: + d_artifact.artifact = existing_by_digest[artifact_digest] for d_content in batch: await self.put(d_content)