Solving the N+1 Query Problem in Rails
Introduction If you鈥檝e worked with Rails for some time, you鈥檝e 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: ...