Avoid n+1 queries on Rails

What's this about?

Master n+1 queries identification, preloading, counts and counter caches, and eliminate n+1 queries from your code.

You will learn:
  • What is an n+1 queries problem
  • When a query will be executed
  • How to preload direct associations
  • How to preload nested associations
  • When should you use the different preloading methods
  • What is the difference between joins and preload
  • What is the difference between count, size and length
  • How to preload just the counts in a list
  • How to solve n+1 queries and slow counts with counter caches
  • What tools can help you detect n+1 queries


Benito Serna

Rubyist, software engineer, working at @briqmx, sharing mostly ruby/rails stuff. Amateur trumpet player