Fix N+1 query on convention/signup_rounds in the My Schedule widget - #11890
Merged
Conversation
Sentry showed a conventions + signup_rounds N+1 (INTERCODE-17E), explicitly left open when the SignupCountPresenter N+1s were fixed in #11880 since it wasn't the same code path. A scheduled check-in (see INTERCODE-17E activity) proposed that this was an unbatched belongs_to :convention lookup in ConventionDrop's products/available_products/ticket_types methods -- verified that hypothesis with a test first, and it didn't hold up: those all load via has_many associations off the single already-loaded convention, so Rails' automatic inverse-of association caching means .convention on each result is already free, fix or no fix. The actual site: {% withdraw_user_signup_button %}, rendered once per signup in the same "My Schedule" widget already fixed once for the bucket/requested_bucket N+1 (#11882), calls signup.event.convention.signup_rounds. UserConProfileDrop#signups preloads event: :event_category but never the event's convention, so each signup's event.convention -- and then .signup_rounds on that fresh Convention instance -- re-queries once per signup. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is |
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.
Summary
Fixes INTERCODE-17E, a
conventions+signup_roundsN+1 that was explicitly left open when theSignupCountPresenterN+1s were fixed in #11880 -- it was a different, unfixed code path even then.Investigation
A scheduled Sentry check-in proposed that this was
ConventionDrop#products/#available_products/#ticket_typescalling.conventionon each result without a preload (product.convention.timezoneinProductDrop/TicketTypeDrop). I wrote a test for that hypothesis first, per usual, and it didn't hold up: those methods all load viahas_manyassociations off the single already-loadedconvention, so Rails' automatic inverse-of association caching means.conventionon each result is already free -- with or without an explicit.includes. Confirmed this and did not carry that dead-end change forward.The actual site, found by re-checking the code that
{% withdraw_user_signup_button %}runs (rendered once per signup in the same "My Schedule" widget already fixed once before for the bucket/requested_bucket N+1 in #11882):UserConProfileDrop#signupsalready preloadsevent: :event_category, but never the event'sconvention-- so each signup'seventis cached, but.conventionon it isn't, and.signup_roundson that freshly-loaded (per-signup)Conventioninstance re-queries too. Addedconvention: :signup_roundsto the existingevent:preload.Test plan
test/liquid_drops/user_con_profile_drop_test.rb, mirroring exactly what the Liquid tag does (signup.event.convention.signup_rounds) -- verified to fail without the fix (10 queries for 5 signups) and pass with it (≤2)test/liquid_drops/suite (41 tests)🤖 Generated with Claude Code