Fix unrelated N+1 queries found during the bucket N+1 investigation - #11883
Merged
nbudin merged 2 commits intoAug 6, 2026
Merged
Conversation
Sentry showed an active_storage_attachments N+1 (INTERCODE-183/188, unrelated to the bucket/registration_policy work) under Event.runs and Event.team_members. Traced it to EventDrop's description/short_blurb/ content_warnings/age_restrictions/participant_communications methods, which each independently called event.images.includes(:blob) to resolve inline image references in markdown -- and since #includes always issues a fresh query regardless of Rails' association cache, rendering N of these fields on the same event fired N separate queries, not just one per event. Memoized the attachment lookup once per EventDrop instance instead. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…ChoiceSignupService Sentry showed a user_con_profiles N+1 (INTERCODE-184/185, unrelated to the bucket/registration_policy work) under Mutation.createMySignup, scaling with the number of existing signups on the run. SignupBucketFinder::FakeSignup.from_signup reads signup.user_con_profile for every existing signup on the run when building its comparison set. EventChangeRegistrationPolicyService already preloaded :user_con_profile before doing this, but EventSignupService#bucket_finder and ExecuteRankedChoiceSignupService#actual_bucket didn't -- brought both in line with the established pattern. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2 tasks
3 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
While chasing the bucket/registration_policy N+1s, the Sentry sweep also turned up a few other N+1 issues clearly unrelated to that work. This PR fixes the two with real scaling impact:
1.
active_storage_attachmentsN+1 (INTERCODE-183/188)EventDrop'sdescription/short_blurb/content_warnings/age_restrictions/participant_communicationsmethods each independently calledevent.images.includes(:blob)to resolve inline image references in markdown..includesalways issues a fresh query regardless of Rails' association cache, so rendering N of these fields on the same event fired N separate queries -- not just one per event as it might look at a glance. Memoized the attachment lookup once perEventDropinstance.2.
user_con_profilesN+1 (INTERCODE-184/185)SignupBucketFinder::FakeSignup.from_signupreadssignup.user_con_profilefor every existing signup on a run when building its comparison set for bucket-finding.EventChangeRegistrationPolicyServicealready preloaded:user_con_profilebefore doing this (from an earlier review pass);EventSignupService#bucket_finderandExecuteRankedChoiceSignupService#actual_bucketdidn't. Brought both in line with the existing pattern.Not fixed here
Also found:
cms_partials(INTERCODE-182, single occurrence) anddeprecated_graph_ql_usagesinsert (INTERCODE-181, not actually an N+1 -- Sentry's detector flagged deprecated-field-usage logging, which is intentional per-operation behavior, not a bug). Neither had enough signal or scaling impact to justify a fix; noting them here for visibility rather than silently dropping them.Test plan
EventDrop: 2 queries → 1, across markdown field calls on the same eventExecuteRankedChoiceSignupService: query count no longer scales with existing-signup count (was 6→26 for 1→20 existing signups; now flat)EventSignupService: 11 queries → 2 for 10 existing signupstest/liquid_drops/,test/services/event_signup_service_test.rb,test/services/execute_ranked_choice_signup_service_test.rb(107 tests)🤖 Generated with Claude Code