Skip to content

Fix N+1 queries on nominations admin changelists - #3086

Merged
JacobCoffee merged 1 commit into
mainfrom
fix-PYDOTORG-PROD-1N8
Aug 11, 2026
Merged

Fix N+1 queries on nominations admin changelists#3086
JacobCoffee merged 1 commit into
mainfrom
fix-PYDOTORG-PROD-1N8

Conversation

@JacobCoffee

Copy link
Copy Markdown
Member

Resolves PYDOTORG-PROD-1N8

`NomineeAdmin.list_display` starts with `__str__`, and `Nominee.__str__`
resolves to `self.user.first_name`, so the changelist issued one
`SELECT users_user...` per row, plus one per row for the `election`
column. `NominationAdmin` hit the same thing through its `nominee`
column, which renders `Nominee.__str__`.

Select the displayed relations in `get_queryset()` on both admins.

Refs PYDOTORG-PROD-1N8

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 11, 2026 18:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes Django admin changelist performance in the nominations app by preloading related objects used in list_display/ordering, eliminating N+1 query patterns when browsing nominees and nominations in the admin.

Changes:

  • Add NomineeAdmin.get_queryset() with select_related("user", "election") to avoid per-row lookups.
  • Add NominationAdmin.get_queryset() with select_related("election", "nominee__user") to avoid per-row lookups for nominee/user and election.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@JacobCoffee
JacobCoffee merged commit b86a6ea into main Aug 11, 2026
13 checks passed
@JacobCoffee
JacobCoffee deleted the fix-PYDOTORG-PROD-1N8 branch August 11, 2026 18:34
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