Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions pulpcore/app/models/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -1119,9 +1121,7 @@ def added(self, base_version=None):
if not base_version:
return Content.objects.filter(version_memberships__version_added=self)

return Content.objects.filter(pk__in=self.content_ids).exclude(
pk__in=base_version.content_ids
)
return Content.objects.filter(pk__in=self.content).exclude(pk__in=base_version.content)

def removed(self, base_version=None):
"""
Expand All @@ -1134,9 +1134,7 @@ def removed(self, base_version=None):
if not base_version:
return Content.objects.filter(version_memberships__version_removed=self)

return Content.objects.filter(pk__in=base_version.content_ids).exclude(
pk__in=self.content_ids
)
return Content.objects.filter(pk__in=base_version.content).exclude(pk__in=self.content)

def contains(self, content):
"""
Expand All @@ -1145,7 +1143,7 @@ def contains(self, content):
Returns:
bool: True if the repository version contains the content, False otherwise
"""
return content.pk in self.content_ids
return content.pk in self.content

def add_content(self, content):
"""
Expand Down
Loading