Skip to content

Fix N+1 queries detected by Bullet#2665

Merged
mroderick merged 1 commit into
masterfrom
bullet-n-plus-one-fixes
Jun 30, 2026
Merged

Fix N+1 queries detected by Bullet#2665
mroderick merged 1 commit into
masterfrom
bullet-n-plus-one-fixes

Conversation

@mroderick

@mroderick mroderick commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

What

Fixes N+1 queries caught by the Bullet gem during development.

Changes

  • Eager load organisers on Workshop and Event queries in the events controller (both upcoming and past views)
  • Eager load organisers on Meeting queries (was causing N+1, same as Workshop and Event)
  • Drop :permissions on Meeting queries -- genuinely unused in this view; includes(:permissions) adds a preload query without reducing the organisers queries (they fire their own SQL join regardless)
  • Keep :venue on Meeting queries -- all 51 meetings have venue_id set in production, and event.venue is accessed in _event.html.haml line 18-20

Verification

  • /events/upcoming loads without Bullet::Notification::UnoptimizedQueryError
  • /events/past loads without Bullet::Notification::UnoptimizedQueryError

@Odaeus Odaeus left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is totally sensible. 👍🏻
If performance on these pages is an issue you could also look at other options like pulling from a DB view or preemptive caching.

@mroderick

Copy link
Copy Markdown
Collaborator Author

If performance on these pages is an issue you could also look at other options like pulling from a DB view or preemptive caching.

I also created #2666, which improves performance considerably.

@mroderick mroderick force-pushed the bullet-n-plus-one-fixes branch 4 times, most recently from 698a7c6 to f3d1fe1 Compare June 30, 2026 08:02
…inate N+1 queries

Bullet detected N+1 queries on Workshop#organisers and Event#organisers
when rendering the events list. Also removed unused permissions eager
loading on Meeting queries, kept venue (used in the view), and added
organisers to fix its N+1.

Meeting analysis:
- venue: used in _event.html.haml line 18-20 (all 51 meetings have
  venue_id in production), kept
- permissions: not directly accessed in view; includes(:permissions)
  doesn't reduce organisers queries (they fire their own SQL join
  regardless), dropped
- organisers: accessed in view line 32-34, was causing N+1, added
@mroderick mroderick force-pushed the bullet-n-plus-one-fixes branch from f3d1fe1 to 1f1ef6a Compare June 30, 2026 08:03
@mroderick mroderick merged commit f4657a5 into master Jun 30, 2026
9 checks passed
@mroderick mroderick deleted the bullet-n-plus-one-fixes branch June 30, 2026 08:08
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.

2 participants