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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)