Read more

Rails: Testing the number of database queries

Dominik Schöler
January 22, 2024Software engineer at makandra GmbH

There are a few tools to combat the dreaded n+1 queries. The bullet gem notifies you of missing eager-loading, and also if there is too much eager-loading. strict_loading in Rails 6.1+ forces developers to explicitly load associations on individual records, for a single association, for an entire model, or globally for all models.

Illustration book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
Read more Show archive.org snapshot

But you can also actually write specs on how many database queries you expect. Use the make_database_queries RSpec matcher from the linked Ruby Gem.

Posted by Dominik Schöler to makandra dev (2024-01-22 15:50)