Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
count number of active record objects instantiated
ActiveSupport::Notifications.subscribe "instantiation.active_record" do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
RequestStore.store[:object_count] ||= 0
RequestStore.store[:object_count] += event.payload[:record_count]
end
ActiveSupport::Notifications.subscribe "process_action.action_controller" do
Rails.logger.info "AR Object count: #{RequestStore.store[:object_count]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment