Skip to content

Instantly share code, notes, and snippets.

@firstrow
Created December 16, 2016 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firstrow/f87e31a513784068fca09df193856a11 to your computer and use it in GitHub Desktop.
Save firstrow/f87e31a513784068fca09df193856a11 to your computer and use it in GitHub Desktop.
active record count queries
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