I found a gem that’s helping me a bunch, so I just wanted to give it a quick mention. After asking people for help on a N+1 query that I couldn’t figure out, one of the people recommended checking out the Goldiloader gem.
I was so impressed that the gem solved my N+1 query so easily, I decided to use it across my site.
It’s ridiculously simple to use once you have model associations defined.
All you need to do is to add the gem to your gemfile and it does the eager loading for you! If there are places you want to avoid eager loading, you can disable Goldiloader for a query.