diff options
Diffstat (limited to 'activerecord/lib/active_record/railties/controller_runtime.rb')
-rw-r--r-- | activerecord/lib/active_record/railties/controller_runtime.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/railties/controller_runtime.rb b/activerecord/lib/active_record/railties/controller_runtime.rb index bc6ca936c0..c5db9b4625 100644 --- a/activerecord/lib/active_record/railties/controller_runtime.rb +++ b/activerecord/lib/active_record/railties/controller_runtime.rb @@ -1,14 +1,23 @@ require 'active_support/core_ext/module/attr_internal' +require 'active_record/log_subscriber' module ActiveRecord module Railties - module ControllerRuntime + module ControllerRuntime #:nodoc: extend ActiveSupport::Concern protected attr_internal :db_runtime + def process_action(action, *args) + # We also need to reset the runtime before each action + # because of queries in middleware or in cases we are streaming + # and it won't be cleaned up by the method below. + ActiveRecord::LogSubscriber.reset_runtime + super + end + def cleanup_view_runtime if ActiveRecord::Base.connected? db_rt_before_render = ActiveRecord::LogSubscriber.reset_runtime @@ -23,7 +32,9 @@ module ActiveRecord def append_info_to_payload(payload) super - payload[:db_runtime] = db_runtime + if ActiveRecord::Base.connected? + payload[:db_runtime] = (db_runtime || 0) + ActiveRecord::LogSubscriber.reset_runtime + end end module ClassMethods |