Fix N+1 query on signup bucket/requested_bucket in UserConProfileDrop - #11882
Merged
Conversation
…#signups Sentry showed a new registration_policy_buckets-by-id N+1 (INTERCODE-186/187/189) after #11880 shipped -- it had been masked by the much larger registration_policy/buckets N+1 that #11880 fixed, and became the dominant N+1 once that one was gone. Traced it to the "My Schedule" widget (the user_signups/signup_bucket_description CMS partials, present by default on most conventions' sites), which calls signup.bucket.name / signup.requested_bucket.name per signup. UserConProfileDrop#signups already preloads several associations but never picked up :bucket/:requested_bucket -- these only became real belongs_to associations in #11871 (they used to be plain string columns needing no extra query at all), so this gap predates #11880 but was previously hidden under the louder N+1. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2 tasks
This was referenced Aug 7, 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.
Summary
After #11880 deployed, Sentry surfaced a new batch of N+1 issues (INTERCODE-186, 187, 189) with the offending query
SELECT registration_policy_buckets.* WHERE id = $1 LIMIT $2, underAppRootLayoutQuery/CmsPageQuery. This is a genuinely different N+1 than the one #11880 fixed -- that one was ahas_manycollection load (registration_policy_buckets WHERE registration_policy_id = X); this one isbelongs_tolookups (bucket/requested_bucketby their own id), so #11880's preload didn't cover it. It's likely this N+1 already existed since #11871 but was masked in Sentry's grouping by the much larger N+1 #11880 just fixed -- once that one went quiet, this one became the dominant signal.Root cause
Traced it (by grepping actual CMS partial content in a production data dump) to a default/stock CMS partial pair present on most conventions' sites --
user_signups/user_signup(the "My Schedule" widget) andsignup_bucket_description, which it renders per signup:{%- elsif signup.bucket.name -%} ... {%- if signup.requested_bucket -%}UserConProfileDrop#signupsbacksuser_con_profile.signupsfor this widget. It already preloads several associations (event,run,rooms,team_members) but never picked up:bucket/:requested_bucket-- these only became realbelongs_toassociations in #11871 (previouslybucket_key/requested_bucket_keywere plain string columns needing no extra query at all), so the widget's preload list was never updated for them.Fix
Added
:bucket,:requested_buckettoUserConProfileDrop#signups's.includes(...). Added a regression test verified to fail without the fix (10 queries for 5 signups) and pass with it (2 total -- one batched query each forbucketandrequested_bucket).Also fixed a pre-existing (unrelated)
Lint/MissingSuperrubocop offense on this same file'sinitialize, since the pre-commit hook rejects it once the file is touched at all.Test plan
test/liquid_drops/user_con_profile_drop_test.rb(new N+1 regression test + full existing suite)test/liquid_drops/suite (39 tests)🤖 Generated with Claude Code