Skip to content

Commit

Permalink
Optimize a query to improve export performance
Browse files Browse the repository at this point in the history
closes #3259

(cherry picked from commit 8e335a0)
  • Loading branch information
dralley authored and patchback[bot] committed Sep 29, 2023
1 parent 27fc2db commit e99ab3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/3259.bugfix
@@ -0,0 +1 @@
Improved performance of exports significantly in some circumstances by optimizing a query.
10 changes: 7 additions & 3 deletions pulp_rpm/app/models/repository.py
Expand Up @@ -264,11 +264,15 @@ def artifacts_for_version(version):
django.db.models.QuerySet: The artifacts that are contained within this version.
"""
qs = Artifact.objects.filter(content__pk__in=version.content)
artifacts_pk = set(
Artifact.objects.filter(content__pk__in=version.content).values_list(
"pulp_id", flat=True
)
)
for tree in DistributionTree.objects.filter(pk__in=version.content):
qs |= tree.artifacts()
artifacts_pk |= set(tree.artifacts().values_list("pulp_id", flat=True))

return qs
return Artifact.objects.filter(pk__in=artifacts_pk)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
Expand Down

0 comments on commit e99ab3f

Please sign in to comment.