Query Diet

Query Diet counts the number of database queries for the last request and subtly displays it in the upper right corner of your screen. The display turns red if too many queries are run, or if they take too long. This is useful to prevent N + 1 queries from creeping into your code.

This is Query Diet being happy about 3 requests taking 66ms:

This is Query Diet being angry about 103 requests taking 164ms:

Installation

Install the gem with

sudo gem install query_diet

There is no further setup necessary after you add the query_diet dependency to your Rails application.

We recommend you only use the gem with the development environment.

Changing warning thresholds

You can define when the counter turns into a red warning. The default threshold is 8 queries and 5000 miliseconds. To change the default, add the following to config/initializers/query_diet.rb:

if defined?(QueryDiet)
  QueryDiet::Logger.bad_count = 8
  QueryDiet::Logger.bad_time = 5000
end

Rails 3 compatibility

We cannot guarantee Rails 3 compatibility at this point, but we will upgrade the gem when Rails 3 is released.

Credits

Henning Koch

makandra.com

gem-session.com