Created
February 4, 2012 16:13
-
-
Save satococoa/1738742 to your computer and use it in GitHub Desktop.
クエリ数をログに出力するSinatra Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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