From 10d95494a1ab54ba158d1ce608fa7ff199324719 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Thu, 16 Jul 2026 16:41:38 +0200 Subject: [PATCH] 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. --- pulpcore/app/models/repository.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pulpcore/app/models/repository.py b/pulpcore/app/models/repository.py index 5be034f5ff..07c4260bf0 100644 --- a/pulpcore/app/models/repository.py +++ b/pulpcore/app/models/repository.py @@ -885,6 +885,10 @@ class Meta: class RepositoryVersionQuerySet(models.QuerySet): """A queryset that provides repository version filtering methods.""" + def get_queryset(self): + # Prevent the content_ids to be automatically hydrated. + return super().get_queryset().defer("content_ids") + def complete(self): return self.filter(complete=True) @@ -997,15 +1001,13 @@ def get_content(self, content_qs=None): if content_qs is None: content_qs = Content.objects - content_ids = self.content_ids - if len(content_ids) >= 65535: - # Workaround for PostgreSQL's limit on the number of parameters in a query - content_ids = ( - RepositoryVersion.objects.filter(pk=self.pk) - .annotate(cids=Func(F("content_ids"), function="unnest")) - .values_list("cids", flat=True) - ) - return content_qs.filter(pk__in=content_ids) + # Try to not even attempt to evaluate the content_ids on the python side. + content_ids_subquery = ( + RepositoryVersion.objects.filter(pk=self.pk) + .annotate(cids=Func(F("content_ids"), function="unnest")) + .values_list("cids", flat=True) + ) + return content_qs.filter(pk__in=content_ids_subquery) @property def content(self):