Skip to content

Instantly share code, notes, and snippets.

@jmccartie
Created April 25, 2011 20:42
Show Gist options
  • Save jmccartie/941175 to your computer and use it in GitHub Desktop.
Save jmccartie/941175 to your computer and use it in GitHub Desktop.
Rails 3 error warning for slow queries
# config/initializers/notifications.rb
# created by @JEG2
if Rails.env == "development"
ActiveSupport::Notifications.subscribe(
"sql.active_record"
) do |_, start, finish, _, details|
time = finish - start
if time >= 0.5
raise "Slow query (#{time}s): #{details[:sql]}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment