Created
August 8, 2019 13:47
-
-
Save thomas-mcdonald/9acc5eea8a875b0566fe5711c7a4a9aa to your computer and use it in GitHub Desktop.
count number of active record objects instantiated
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
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