Skip to content

[PR #7603/262c83d2 backport][3.105] Optimize protected_versions() to avoid expensive JOINs#7610

Merged
dralley merged 1 commit into3.105from
patchback/backports/3.105/262c83d23114fd2e5bd149877d805596b453a0b5/pr-7603
Apr 19, 2026
Merged

[PR #7603/262c83d2 backport][3.105] Optimize protected_versions() to avoid expensive JOINs#7610
dralley merged 1 commit into3.105from
patchback/backports/3.105/262c83d23114fd2e5bd149877d805596b453a0b5/pr-7603

Conversation

@patchback
Copy link
Copy Markdown

@patchback patchback bot commented Apr 19, 2026

This is a backport of PR #7603 as merged into main (262c83d).

The protected_versions() method was building a single queryset using |= (OR) operations that caused Django to generate a LEFT OUTER JOIN on core_publication across all repository versions (10,000+ rows), resulting in queries taking minutes in large databases.

Rewritten to collect protected version PKs from separate simple queries against Distribution and Publication tables, then return a simple filter(pk__in=...).

Also defer the content_ids ArrayField in cleanup_old_versions since it can contain hundreds of thousands of UUIDs per version and is not needed by version.delete().

fixes: #7594

Assisted By: claude-opus-4.6

📜 Checklist

  • Commits are cleanly separated with meaningful messages (simple features and bug fixes should be squashed to one commit)
  • A changelog entry or entries has been added for any significant changes
  • Follows the Pulp policy on AI Usage
  • (For new features) - User documentation and test coverage has been added

See: Pull Request Walkthrough

The protected_versions() method was building a single queryset using |= (OR)
operations that caused Django to generate a LEFT OUTER JOIN on core_publication
across all repository versions (10,000+ rows), resulting in queries taking
minutes in large databases.

Rewritten to collect protected version PKs from separate simple queries against
Distribution and Publication tables, then return a simple filter(pk__in=...).

Also defer the content_ids ArrayField in cleanup_old_versions since it can
contain hundreds of thousands of UUIDs per version and is not needed by
version.delete().

fixes: #7594

Assisted By: claude-opus-4.6

(cherry picked from commit 262c83d)
@dralley dralley enabled auto-merge (rebase) April 19, 2026 04:33
@dralley dralley merged commit 9c071b7 into 3.105 Apr 19, 2026
14 checks passed
@dralley dralley deleted the patchback/backports/3.105/262c83d23114fd2e5bd149877d805596b453a0b5/pr-7603 branch April 19, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants