Skip to content

Commit

Permalink
Enhance get_content() by omitting the version_membership lookup
Browse files Browse the repository at this point in the history
>>> timeit.timeit("len(v.get_content(Package.objects).only('pk'))", globals=globals(), number=10)
105.0813707895577
>>> timeit.timeit("len(v.get_content2(Package.objects).only('pk'))", globals=globals(), number=10)
58.41291802749038
>>> timeit.timeit("v.get_content(Package.objects).count()", globals=globals(), number=10)
62.557361379265785
>>> timeit.timeit("v.get_content2(Package.objects).count()", globals=globals(), number=10)
16.70007463544607

Credits to @newswangerd.

closes #3969
  • Loading branch information
lubosmj committed Aug 17, 2023
1 parent 89d37d1 commit 019266a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/3969.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved the performance when looking up content for repository versions.
2 changes: 1 addition & 1 deletion pulpcore/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def get_content(self, content_qs=None):
if content_qs is None:
content_qs = Content.objects

return content_qs.filter(version_memberships__in=self._content_relationships())
return content_qs.filter(pk__in=self._content_relationships().values_list("content_id"))

@property
def content(self):
Expand Down

0 comments on commit 019266a

Please sign in to comment.