All Books! All Books

Avoid n+1 queries on Rails

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

What is “Avoid n+1 queries on Rails” about?

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

Who should read “Avoid n+1 queries on Rails”?

For beginner programmers

What will you learn in “Avoid n+1 queries on Rails”

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