Solving the N+1 Query Problem in Rails
Introduction If you’ve worked with Rails for some time, you’ve probably seen performance issues that did not make much sense at first. One of the usual suspects is the N+1 query problem. It is easy to miss, and it can quietly slow things down as your data grows. What is the N+1 Problem? In simple terms: You load a list of records (1 query) Then Rails runs one query per record to fetch associated data A quick example: ...