Benito Serna Tips and tools for Ruby on Rails developers

Tool to run the benchmark for fixes for the latest-comment n+1 queries problem

November 14, 2020

What fix should you pick for your “latest-comment” n+1 queries problem?

One example of this problem is trying to get the latest comment on a list of posts, but there are others, like the last review in a list of products, or the cheapest price, or the latest payment for each costumer, etc…

I have already shared some fixes to help you solve the problem. and some benchmarks for this fixes….

This is the code that I use to run those benchmarks. You can use it to play with the code and seed values, to make it more specific to your current problem.

Benchmark structure

The benchmark will include the memory and the “iterations per second” benchmarks.

With this “reports"…

The link

You can see the code on github at bhserna/latest_comment_n-1_fixes_benchmark

Related articles

No more… “Why active record is ignoring my includes?”

Get for free the first part of the ebook Fix n+1 queries on Rails that will help you:

  • Explain what is an n+1 queries problem
  • Identify when ActiveRecord will execute a query
  • Solve the latest comment example
  • Detect n+1 queries by watching the logs
  • Learn the tools to detect n+1 queries
Get the first part of the ebook for free