Skip to content

Optimize protected_versions() to avoid expensive JOINs#7603

Merged
dralley merged 1 commit intopulp:mainfrom
git-hyagi:update-cleanup_old_versions-method
Apr 19, 2026
Merged

Optimize protected_versions() to avoid expensive JOINs#7603
dralley merged 1 commit intopulp:mainfrom
git-hyagi:update-cleanup_old_versions-method

Conversation

@git-hyagi
Copy link
Copy Markdown
Contributor

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: pulp#7594

Assisted By: claude-opus-4.6
@dralley dralley merged commit 262c83d into pulp:main Apr 19, 2026
13 of 14 checks passed
@patchback
Copy link
Copy Markdown

patchback bot commented Apr 19, 2026

Backport to 3.105: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.105/262c83d23114fd2e5bd149877d805596b453a0b5/pr-7603

Backported as #7610

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@patchback
Copy link
Copy Markdown

patchback bot commented Apr 19, 2026

Backport to 3.108: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.108/262c83d23114fd2e5bd149877d805596b453a0b5/pr-7603

Backported as #7611

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repository Version deletion is slow after creating a new repository version

2 participants