Fix N + 1 queries and introduce Prosopite gem#72400
Draft
Fix N + 1 queries and introduce Prosopite gem#72400
Conversation
- Use Claude to surface existing N + 1 queires
- Install Bullet gem in dev and test group
to catch other/new N + 1 queires
Signed-off-by: Nick Lathe <nick.lathe@code.org>
f8144eb to
a062144
Compare
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.
Benchmark Results
Query counts measured with ActiveSupport::Notifications on sql.active_record, median of 3 runs per scenario. Each scenario runs the same code path twice — once without includes (before) and once with the eager loading fix (after) — against a local dev database.
Sample Between Using 'includes'
80% total query reduction across benchmarked scenarios. Improvements scale linearly with record count — production workloads with larger result sets will see proportionally larger gains.
Diff Between Active Record Calls in development.log
Grep'ing the development.log after 3 refreshes of page, comparing before (staging) and after (feature branch) of total accumulated Active Record times:
Before Change
Started GET "/teacher_dashboard/home"resulted in a median Active Record time of893 msAfter Change
Started GET "/teacher_dashboard/home"resulted in a median Active Record time of179 msLinks
Testing story
Deployment notes
Privacy and security