Created
February 9, 2016 15:32
-
-
Save crazymykl/b526e0ed6b285b3c4e77 to your computer and use it in GitHub Desktop.
A way to count the number of queries the passed block causes.
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
def count_queries(&blk) | |
x = 0 | |
counter = -> (*args) { x += 1 } | |
ActiveSupport::Notifications.subscribed counter, 'sql.active_record', &blk | |
x | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment