Skip to content

Instantly share code, notes, and snippets.

@thomas-mcdonald
Created August 8, 2019 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 thomas-mcdonald/9acc5eea8a875b0566fe5711c7a4a9aa to your computer and use it in GitHub Desktop.
Save thomas-mcdonald/9acc5eea8a875b0566fe5711c7a4a9aa to your computer and use it in GitHub Desktop.
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