Created
December 16, 2016 13:47
-
-
Save firstrow/f87e31a513784068fca09df193856a11 to your computer and use it in GitHub Desktop.
active record count queries
This file contains hidden or 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
def count_queries(&block) | |
p "--------- Start Count SQL -----------" | |
count = 0 | |
counter_f = ->(name, started, finished, unique_id, payload) { | |
unless payload[:name].in? %w[ CACHE SCHEMA ] | |
count += 1 | |
end | |
} | |
ActiveSupport::Notifications.subscribed(counter_f, "sql.active_record", &block) | |
count | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment