Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the QuerySet for public archive view #712

Open
miggol opened this issue Oct 3, 2024 · 0 comments
Open

Fix the QuerySet for public archive view #712

miggol opened this issue Oct 3, 2024 · 0 comments
Labels
Technical Not interesting for secretary

Comments

@miggol
Copy link
Contributor

miggol commented Oct 3, 2024

Sentry has brought an N+1 query to our attention. An N+1 query describes a situation in which you fetch data from the DB, then for each entry you fetch more data from the DB, and so on, until you're hitting the DB with a gazillion queries.

Normally we're not super strict about optimization but considering that this is one of our few public-facing pages we should at least not have it be a potential DOS target.

What (I think) is happening with the public archive is that we're getting a QS of all public proposals, and then in the template we're hitting the database with proposal.reviewing_committee.name for every single item. Because reviewing_committee.name traverses a ForeignKey relationship into the Groups DB this becomes an expensive N+1 query situation.

This can be resolved by annotating the proposals QS with the relevant data in the view, or using select_related().

@miggol miggol added the Technical Not interesting for secretary label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Technical Not interesting for secretary
Projects
None yet
Development

No branches or pull requests

1 participant