Fix N+1 queries on registration_policy and its buckets - #11869
Merged
Conversation
EventType/EventProposalType read registration_policy directly and RegistrationPolicyType read buckets (and every field derived from it) via plain, unbatched associations, so any query touching these across a list of events issued one query per row instead of one batched query for the whole list. Wire both associations into this codebase's existing association_loaders dataloader pattern instead. Also disable Metrics/ClassLength and Metrics/BlockLength project-wide; we were already granting per-file exceptions to both cops consistently enough that keeping them enabled wasn't adding value. Fixes INTERCODE-176, INTERCODE-177 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Run bin/rails graphql:update to pick up the schema/type changes from the registration_policy N+1 fix. schema.graphql/schema.json hadn't been regenerated since a prior merge (May 28), so this also catches up ~2 months of accumulated description/field drift from unrelated merged PRs that didn't run this step. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The N+1 fix PR needed a bin/rails graphql:update run that hadn't been done in ~2 months of merged PRs. Add it to CLAUDE.md so future schema-touching changes catch this before committing instead of after. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Matches the inline-disable style already used elsewhere in this file (e.g. GraphQL/ExtractType on field declarations) instead of disable/enable pairs. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is |
4 tasks
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
EventType/EventProposalTypereadregistration_policydirectly, andRegistrationPolicyTypereadbuckets(and every field derived from it —minimum_slots,total_slots,slots_limited, etc.) via plain, unbatched associations. Any query touching these across a list of events issued one query per row instead of one batched query for the whole list — this is the referential-integrity gap left over from the JSONB→AR migration in Migrate registration policies from JSONB to ActiveRecord (#11238) #11819.association_loadersdataloader pattern instead (seeapp/graphql/sources/active_record_association.rb), matching how every other association is already batched in these types.Metrics/ClassLengthandMetrics/BlockLengthproject-wide — we were already granting per-file exceptions to both cops consistently enough that keeping them enabled wasn't adding value, and it was blocking this fix on unrelated pre-existing debt inevent_type.rb.bin/rails graphql:updateto regenerateschema.graphql/schema.jsonand the generated frontend types. This picked up ~2 months of accumulated, unrelated description/field drift from prior merged PRs that hadn't run this step (last regenerated May 28) — so most of that diff is pre-existing catch-up, not new from this change. Added a note toCLAUDE.mdso future schema-touching PRs run this before committing.Fixes INTERCODE-176, INTERCODE-177 (both are the same root cause, confirmed by reproducing each Sentry trace's exact query shape locally before and after the fix).
Test plan
bin/rails test test/graphql/mutations/{create_event,create_event_proposal,create_filler_event,update_event,update_event_proposal}_test.rb— 17 tests, 0 failuresregistrationPolicy/slotsLimited/totalSlotsacross 8 events): query count went from 1 (policies) + up to 16 (buckets, one per event) down to a flat 2 queries regardless of event countbin/rails graphql:updateran clean, no manual edits needed to generated filesPR description written by Claude