Skip to content

Fix N + 1 queries and introduce Prosopite gem#72400

Draft
nicklathe wants to merge 3 commits intostagingfrom
nicklathe/fix-n-plus-one
Draft

Fix N + 1 queries and introduce Prosopite gem#72400
nicklathe wants to merge 3 commits intostagingfrom
nicklathe/fix-n-plus-one

Conversation

@nicklathe
Copy link
Copy Markdown
Contributor

@nicklathe nicklathe commented Apr 28, 2026

  • Use Claude to surface existing N + 1 queires
  • Install Prosopite gem in dev and test group to catch other/new N + 1 queires

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'

------------------------------------------------------------------------------
Scenario                                   Before    After    Saved Records
------------------------------------------------------------------------------
SectionInstructors#index                       11        3      73% (5 records)
Unit#with_seed_models                          82       21      74% (20 records)
CurriculumPdfs#get_pdf_enabled_scripts         51        3      94% (50 records)
LTI#section_instructors                         5        3      40% (4 records)
------------------------------------------------------------------------------
TOTAL                                         149       30      80%

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 of 893 ms

After Change
Started GET "/teacher_dashboard/home" resulted in a median Active Record time of 179 ms

Links

  • Jira:

Testing story

Deployment notes

Privacy and security

@nicklathe nicklathe changed the title Fix N + 1 queries and introduce Bullet gem Fix N + 1 queries and introduce Prosopite gem Apr 30, 2026
  - 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>
  - Switch to prosopite vs. bullet
  - Address more n+1 queries
@nicklathe nicklathe force-pushed the nicklathe/fix-n-plus-one branch from f8144eb to a062144 Compare April 30, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant