Skip to content

Commit 10d9549

Browse files
committed
WIP Improve content_ids handling by defered loading
The array_field can be huge and most of the time we don't need the values in python. Some uses can even be handled by clever SQL without ever channelling all the data through the network.
1 parent 5a8bcc1 commit 10d9549

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

pulpcore/app/models/repository.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,10 @@ class Meta:
885885
class RepositoryVersionQuerySet(models.QuerySet):
886886
"""A queryset that provides repository version filtering methods."""
887887

888+
def get_queryset(self):
889+
# Prevent the content_ids to be automatically hydrated.
890+
return super().get_queryset().defer("content_ids")
891+
888892
def complete(self):
889893
return self.filter(complete=True)
890894

@@ -997,15 +1001,13 @@ def get_content(self, content_qs=None):
9971001
if content_qs is None:
9981002
content_qs = Content.objects
9991003

1000-
content_ids = self.content_ids
1001-
if len(content_ids) >= 65535:
1002-
# Workaround for PostgreSQL's limit on the number of parameters in a query
1003-
content_ids = (
1004-
RepositoryVersion.objects.filter(pk=self.pk)
1005-
.annotate(cids=Func(F("content_ids"), function="unnest"))
1006-
.values_list("cids", flat=True)
1007-
)
1008-
return content_qs.filter(pk__in=content_ids)
1004+
# Try to not even attempt to evaluate the content_ids on the python side.
1005+
content_ids_subquery = (
1006+
RepositoryVersion.objects.filter(pk=self.pk)
1007+
.annotate(cids=Func(F("content_ids"), function="unnest"))
1008+
.values_list("cids", flat=True)
1009+
)
1010+
return content_qs.filter(pk__in=content_ids_subquery)
10091011

10101012
@property
10111013
def content(self):

0 commit comments

Comments
 (0)