From e99ab3f0f1d221683cbcd092b72cc133e03ebf0d Mon Sep 17 00:00:00 2001 From: Daniel Alley Date: Thu, 28 Sep 2023 16:41:57 -0400 Subject: [PATCH] Optimize a query to improve export performance closes #3259 (cherry picked from commit 8e335a02184454d277090d05d30347d3a9ff7bda) --- CHANGES/3259.bugfix | 1 + pulp_rpm/app/models/repository.py | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 CHANGES/3259.bugfix diff --git a/CHANGES/3259.bugfix b/CHANGES/3259.bugfix new file mode 100644 index 000000000..907345e8a --- /dev/null +++ b/CHANGES/3259.bugfix @@ -0,0 +1 @@ +Improved performance of exports significantly in some circumstances by optimizing a query. diff --git a/pulp_rpm/app/models/repository.py b/pulp_rpm/app/models/repository.py index dee378f2e..45a6c13d7 100644 --- a/pulp_rpm/app/models/repository.py +++ b/pulp_rpm/app/models/repository.py @@ -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"