DEV Community

Play Button Pause Button
AppMap Ruby for AppMap

Posted on

Find the N+1 Query Problem in Rails Apps in Under 5 Mins

This video is based on the brilliant Eager Loading and the N+1 Query Problem blog post by Kevin Gilpin.

It is a short demonstration of how to identify the N+1 Query anti-pattern using the AppMap extension for VS Code, jq and the Rails Sample Application Sixth Edition as an example.

The N+1 anti-pattern happens when a query is executed for every result of a previous query. If left unchecked N+1 queries result in a gradual slowdown in the performance of an application.

N+1 Query Problem

Detecting  N+1 queries is tricky, because they are not revealed by any mainstream testing strategy.

To detect the N+1 query problems we need to look at the number of SQL queries that are performed in a realistic situation, such as an integration test, and compare this number with a “reasonable” expectation.

You can find full usage instructions, and all these links, on the AppMap page in the VSCode marketplace.

Thanks for watching!

Top comments (0)