Skip to content

Fix N+1 queries on admin workshop show - #2797

Merged
mroderick merged 1 commit into
masterfrom
fix/admin-workshop-nplus1
Aug 9, 2026
Merged

Fix N+1 queries on admin workshop show#2797
mroderick merged 1 commit into
masterfrom
fix/admin-workshop-nplus1

Conversation

@mroderick

@mroderick mroderick commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Closes #2796

Summary

The admin workshop show page issued ~6 scoped workshop_invitations queries per attending row, because with_notes_and_their_authors preloads member_notes/attendance_warnings but not the member's other workshop invitations. For /admin/workshops/3824 that 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_members query 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

  • Query-object spec (spec/queriers/admin_workshop_attendee_flags_spec.rb): semantics preserved, query count constant as member count grows.
  • Regression guard on the show page: bounded query count.
  • Measured against codebar_production_dump: flag computation 5 queries / 26ms for 27 attendees (old path ~159).
  • 148 controller/request/querier examples green; rubocop clean.

Measured performance

/admin/workshops/3824 (4,364 invitations, 27 attending) against the production dump, same session.

Metric master this PR
Queries 205 (38 cached) 35 (4 cached)
SQL issued per attendance row 7 0

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.

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
mroderick marked this pull request as draft August 9, 2026 07:28
@mroderick
mroderick force-pushed the fix/admin-workshop-nplus1 branch from 6f89a35 to 2380b3c Compare August 9, 2026 07:29
@mroderick mroderick changed the title Fix admin workshop show N+1 and 4,337-item dropdown (was ~92s) Fix N+1 queries on admin workshop show Aug 9, 2026
@mroderick
mroderick marked this pull request as ready for review August 9, 2026 10:49
@mroderick
mroderick merged commit f97b60b into master Aug 9, 2026
10 checks passed
@mroderick
mroderick deleted the fix/admin-workshop-nplus1 branch August 9, 2026 11:06
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.

Admin workshop show is slow (N+1 + 4,337-item dropdown) — 92s for /admin/workshops/3824

2 participants