Benito Serna
Ruby/Rails, TDD, Software...

Cheatsheet to help you decide which fix for the last-comment n+1 problem is the best for you

Do you have to fetch the latest “x” of each record? Not sure how to avoid the n+1 queries?

Hopefully you will find different ways to solve it. But what is the one that you should use?

You can search the internet, but opinions can be overwhelming and confusing, and most of the time not specific to your specific usecase.

I have already shared some fixes that to solve the “latest comment” n+1 queries problem and some benchmarks for this 5 fixes

Now I want to share with you a little cheatsheet to help you decide which fix to pick in different contexts, based mostly on my interpretation of the benchmarks and the complexity of each solution.

Get it here: Cheatsheet for the “latest-comment” n+1 queries problem

I hope it can help you =)