Audit::Ovl
Audit::Ovl is a Rails middleware that tracks the number of SQL queries executed per request. It helps you identify N+1 queries and enforce performance budgets by logging warnings or raising errors when a request exceeds a specified query limit.
Installation
Add this line to your application's Gemfile:
gem 'audit_ovl'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install audit_ovl
Usage
You can configure the query budget and the action to take when the budget is exceeded in an initializer (e.g., config/initializers/audit_ovl.rb).
# config/initializers/audit_ovl.rb
Audit::Ovl.configure do |config|
# Set the maximum number of SQL queries allowed per request (default: 50)
config.budget = 30
# Set the action to take when the budget is exceeded.
# Options:
# :log - Log a warning (default)
# :raise - Raise an error (RuntimeError)
config.action = :log # or :raise
# Optional: Provide a custom logger (default: Logger.new(STDOUT))
# config.logger = Rails.logger
end
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/audit_ovl.