Skip to content

Fix N+1 queries on identity in UsersController and BoardsController#2365

Merged
flavorjones merged 2 commits intobasecamp:mainfrom
secretpray:ref/active-record-optimization
Feb 25, 2026
Merged

Fix N+1 queries on identity in UsersController and BoardsController#2365
flavorjones merged 2 commits intobasecamp:mainfrom
secretpray:ref/active-record-optimization

Conversation

@secretpray
Copy link
Contributor

Summary

  • Add .includes(:identity) to UsersController#index to preload identities when rendering user JSON (fixes N+1 on user.identity.email_address)
  • Add .includes(creator: :identity) to BoardsController#index to preload board creators with their identities
  • Add .includes(:identity) to BoardsController#edit for the users list

Test plan

  • Added N+1 regression tests for UsersController#index and BoardsController#index
  • Tests verify exactly 1 query per association (no N+1)
  • bin/rails test test/controllers/users_controller_test.rb test/controllers/boards_controller_test.rb

secretpray and others added 2 commits February 25, 2026 12:45
- Add .includes(:identity) to UsersController#index
- Add .includes(creator: :identity) to BoardsController#index
- Add N+1 regression tests for both controllers
@flavorjones flavorjones force-pushed the ref/active-record-optimization branch from 374c136 to cd09541 Compare February 25, 2026 18:07
@flavorjones
Copy link
Member

@secretpray Thanks for this, great find. I rebased and added a commit that simplified the tests significantly.

@flavorjones flavorjones merged commit 446f22a into basecamp:main Feb 25, 2026
5 checks passed
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