Skip to content

Instantly share code, notes, and snippets.

@satococoa
Created February 4, 2012 16:13
Show Gist options
  • Save satococoa/1738742 to your computer and use it in GitHub Desktop.
Save satococoa/1738742 to your computer and use it in GitHub Desktop.
クエリ数をログに出力するSinatra Extension
require 'sinatra/base'
# app.rb で register Sinatra::QueryReporter
module Sinatra
module QueryReporter
def self.registered(app)
query_count = 0
subscriber = ''
app.before do
query_count = 0
subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
query_count += 1
end
end
app.after do
logger.debug, "QueryReporter: #{query_count}"
ActiveSupport::Notifications.unsubscribe(subscriber)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment