Fix N+1 queries on admin workshop show - #2797
Merged
Merged
Conversation
The admin workshop show page issued ~6 scoped workshop_invitations queries per attending row (newbie?, flag_to_organisers?, recent_notes) because with_notes_and_their_authors preloads member_notes and attendance_warnings but not the member's other workshop invitations. For /admin/workshops/3824 this was 210 queries / 51s DB / 40s view / 221M allocations (~92s total). Collapse the three per-row lookups into a bounded query object (AdminWorkshopAttendeeFlags.for_members) computed once and memoised on the loaded member instances. 27 attendees now need 5 queries instead of ~159. Fixes #2796
mroderick
marked this pull request as draft
August 9, 2026 07:28
mroderick
force-pushed
the
fix/admin-workshop-nplus1
branch
from
August 9, 2026 07:29
6f89a35 to
2380b3c
Compare
mroderick
marked this pull request as ready for review
August 9, 2026 10:49
KimberleyCook
approved these changes
Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2796
Summary
The admin workshop show page issued ~6 scoped
workshop_invitationsqueries per attending row, becausewith_notes_and_their_authorspreloadsmember_notes/attendance_warningsbut not the member's other workshop invitations. For/admin/workshops/3824that was 210 queries / 51s DB / 40s view / 221M allocations (~92s total).This PR is scoped to the N+1 fix only. The RSVP dropdown itself is handled separately in #2798 (which replaces it with a dedicated RSVP page).
Fix
A new
AdminWorkshopAttendeeFlags.for_membersquery object collapses the three per-row lookups (newbie?,flag_to_organisers?,recent_notes) into a bounded set of aggregate queries, computed once and memoised on the loaded member instances. 27 attendees now need 5 queries instead of ~159.Verification
spec/queriers/admin_workshop_attendee_flags_spec.rb): semantics preserved, query count constant as member count grows.codebar_production_dump: flag computation 5 queries / 26ms for 27 attendees (old path ~159).Measured performance
/admin/workshops/3824(4,364 invitations, 27 attending) against the production dump, same session.End-to-end (browser dev-tools
DomContentLoaded): ~119 s on master vs ~118 s here.The N+1 fix removes ~6 queries per attendee row and ~90% of the query load, lowering DB/server pressure. It does not change perceived page load, because the remaining cost is the 4,337-option RSVP
<select>(a ~9 s server render plus a large HTML body the browser takes ~100 s to receive and parse). Removing that dropdown is #2798; the two PRs are complementary and the user-facing speedup comes from merging both.