fix: homepage performance - missing indexes and inefficient queries#2506
Merged
olleolleolle merged 2 commits intocodebar:masterfrom Feb 24, 2026
Merged
fix: homepage performance - missing indexes and inefficient queries#2506olleolleolle merged 2 commits intocodebar:masterfrom
olleolleolle merged 2 commits intocodebar:masterfrom
Conversation
- Add composite indexes on (member_id, attending) and (event_id, attending) for workshop_invitations, meeting_invitations, and invitations tables - Replace inefficient total_upcoming_events_count that loaded all workshops with simple COUNT queries
- EventPresenter#organisers now uses model.organisers instead of model.permissions.find_by which bypasses eager loading - WorkshopPresenter#organisers uses model.organisers with fallback to chapter_organisers for backwards compatibility
KimberleyCook
approved these changes
Feb 24, 2026
olleolleolle
approved these changes
Feb 24, 2026
Collaborator
olleolleolle
left a comment
There was a problem hiding this comment.
Nice to only count those! And to get the presenters fixed!
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
Fixes the 503 timeout on the homepage (Heroku 30s timeout) caused by performance issues introduced in #2503.
Root Cause Analysis
Problem 1: Missing Database Indexes
The code changes in #2503 introduced new methods that query invitations filtered by
attending: true:The
acceptedscope filters on theattendingcolumn, but there were no indexes on(member_id, attending)or(event_id, attending), causing full table scans.Problem 2: Inefficient
total_upcoming_events_countThis loaded ALL workshops in the database with expensive JOINs (including polymorphic permissions) just to get a count.
Problem 3: Presenters Bypass Eager Loading
The dashboard queries workshops with
eager_load(:permissions), but the presenters ignored this and made their own queries:This triggered additional queries per event, defeating the purpose of eager loading.
Fixes Applied
1. Database Migration
Added composite indexes for invitation queries:
2. Optimized Event Counter
3. Use Eager-Loaded Associations
The presenters now use the
model.organisersassociation (which uses the eager-loaded permissions) instead of making additional queries.Testing
Deployment
Run the migration on production:
bundle exec rails db:migrate