Just the right amount of Rails eager loading
open sourceMITself-hostablefree
Goldiloader removes most N+1 queries in Active Record without anyone writing includes: the first time code reaches an association on one record from a query, it eager loads that association for every record the query returned, however deeply nested. It assumes records from one query are used the same way, and you can turn it off for a query (auto_include(false)) or an association, or still eager load by hand. The current branch supports Rails 7.2 and later with Ruby 3.2 and later.
Problems it solves
- I'm tired of adding includes everywhere to fix N+1 queries
- make ActiveRecord eager load associations automatically when they're used
- N+1 queries keep coming back every time someone changes a view
- load the posts for all five blogs in one query without changing the code
- fix N+1 queries across a big legacy Rails app at once
- eager loading by hand breaks when the view decides what it needs
- automatic batching of association loads in Rails
Features
- automatic eager loading on first access
- nested associations
- auto_include(false) per query
- per-association opt-out
- works alongside includes, preload and eager_load
Alternatives
The same job
These do what Goldiloader does.
