Skip to content

rubysamurai/query_count

Folders and files

NameName
Last commit message
Last commit date

Latest commit

43c68b4 · Feb 13, 2022

History

25 Commits
Jan 25, 2022
May 21, 2020
Jan 25, 2022
Feb 13, 2022
Jan 25, 2022
May 22, 2020
May 21, 2020
Jan 25, 2022
Feb 13, 2022
Dec 16, 2020
May 21, 2020
Jan 25, 2022
May 21, 2020
Jan 25, 2022

Repository files navigation

Query Count

Gem Version CI

A zero-configuration gem to count the number of SQL queries performed by the ActiveRecord. Supports Rails 4.2+ and Ruby 2.0+ (the complete testing matrix is here).

Installation

Add this line to your application's Gemfile:

gem 'query_count'

Run bundle install.

Usage

The gem will automatically include the number of SQL queries to the default Rails log.

ActiveRecord: 34.0ms | SQL Queries: 8 (1 cached)

This log example shows that the total number of queries was 8, and 1 was cached, which means the request hit the database 7 times.

QueryCount::Counter provides public methods counter, counter_cache, reset_counter, reset_counter_cache.

RSpec 3 example:

it 'performs exactly 5 queries' do
  QueryCount::Counter.reset_counter
  5.times { User.last }
  expect(QueryCount::Counter.counter).to eq 5
end

License

query_count © Dmitriy Tarasov. Released under the MIT license.