Skip to content

Commit 3b22794

Browse files
author
Andrew Cheng
committed
implement unnesting and add a temporary changelog
1 parent 282c840 commit 3b22794

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Added a ``base_version`` filter to the content list endpoints. When combined with
2+
``repository_version_added`` or ``repository_version_removed``, it returns the net set of content
3+
added or removed between two arbitrary repository versions instead of only the single-step
4+
difference against the filtered version's immediate predecessor. The diff is computed database-side
5+
via ``unnest`` subqueries over each version's ``content_ids``, avoiding loading the arrays into
6+
memory or passing them as per-query parameters.

pulpcore/app/models/repository.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,13 +1000,26 @@ def get_content(self, content_qs=None):
10001000
content_ids = self.content_ids
10011001
if len(content_ids) >= 65535:
10021002
# 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-
)
1003+
content_ids = self.content_ids_subquery()
10081004
return content_qs.filter(pk__in=content_ids)
10091005

1006+
def content_ids_subquery(self):
1007+
"""
1008+
Return this version's ``content_ids`` as a database-side ``unnest`` subquery.
1009+
1010+
Using a subquery keeps the content unit UUIDs inside PostgreSQL instead of loading the
1011+
whole array into Python and passing each UUID as a bound query parameter. This avoids the
1012+
per-query parameter limit and the memory/serialization cost for large repository versions.
1013+
1014+
Returns:
1015+
django.db.models.QuerySet: A values queryset yielding the content unit UUIDs.
1016+
"""
1017+
return (
1018+
RepositoryVersion.objects.filter(pk=self.pk)
1019+
.annotate(cids=Func(F("content_ids"), function="unnest"))
1020+
.values_list("cids", flat=True)
1021+
)
1022+
10101023
@property
10111024
def content(self):
10121025
"""
@@ -1119,8 +1132,8 @@ def added(self, base_version=None):
11191132
if not base_version:
11201133
return Content.objects.filter(version_memberships__version_added=self)
11211134

1122-
return Content.objects.filter(pk__in=self.content_ids).exclude(
1123-
pk__in=base_version.content_ids
1135+
return Content.objects.filter(pk__in=self.content_ids_subquery()).exclude(
1136+
pk__in=base_version.content_ids_subquery()
11241137
)
11251138

11261139
def removed(self, base_version=None):
@@ -1134,8 +1147,8 @@ def removed(self, base_version=None):
11341147
if not base_version:
11351148
return Content.objects.filter(version_memberships__version_removed=self)
11361149

1137-
return Content.objects.filter(pk__in=base_version.content_ids).exclude(
1138-
pk__in=self.content_ids
1150+
return Content.objects.filter(pk__in=base_version.content_ids_subquery()).exclude(
1151+
pk__in=self.content_ids_subquery()
11391152
)
11401153

11411154
def contains(self, content):

0 commit comments

Comments
 (0)