diff options
-rw-r--r-- | actionpack/test/activerecord/controller_runtime_test.rb | 13 | ||||
-rw-r--r-- | activerecord/lib/active_record/railties/controller_runtime.rb | 5 |
2 files changed, 18 insertions, 0 deletions
diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb index c030315d2b..b87b9f9c47 100644 --- a/actionpack/test/activerecord/controller_runtime_test.rb +++ b/actionpack/test/activerecord/controller_runtime_test.rb @@ -11,6 +11,10 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase def show render :inline => "<%= Project.all %>" end + + def zero + render :inline => "Zero DB runtime" + end end include ActiveSupport::LogSubscriber::TestHelper @@ -39,4 +43,13 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase assert_equal 2, @logger.logged(:info).size assert_match(/\(Views: [\d.]+ms \| ActiveRecord: [\d.]+ms\)/, @logger.logged(:info)[1]) end + + def test_runtime_reset_before_requests + ActiveRecord::LogSubscriber.runtime += 12345 + get :zero + wait + + assert_equal 2, @logger.logged(:info).size + assert_match(/\(Views: [\d.]+ms \| ActiveRecord: 0.0ms\)/, @logger.logged(:info)[1]) + end end diff --git a/activerecord/lib/active_record/railties/controller_runtime.rb b/activerecord/lib/active_record/railties/controller_runtime.rb index bc6ca936c0..a0eecf4f46 100644 --- a/activerecord/lib/active_record/railties/controller_runtime.rb +++ b/activerecord/lib/active_record/railties/controller_runtime.rb @@ -9,6 +9,11 @@ module ActiveRecord attr_internal :db_runtime + def process_action(action, *args) + ActiveRecord::LogSubscriber.reset_runtime + super + end + def cleanup_view_runtime if ActiveRecord::Base.connected? db_rt_before_render = ActiveRecord::LogSubscriber.reset_runtime |