Skip to content
Browse files

Take into account time spent in AR even if a redirect occurs or if it…

… is after the render
  • Loading branch information...
1 parent 4ee7d92 commit 8a722e09122a2beeb122a8931a08b72c46d6bc50 @fcheung fcheung committed May 22, 2011
View
26 actionpack/test/activerecord/controller_runtime_test.rb
@@ -15,6 +15,17 @@ def show
def zero
render :inline => "Zero DB runtime"
end
+
+ def redirect
+ Project.all
+ redirect_to :action => 'show'
+ end
+
+ def db_after_render
+ render :inline => "Hello world"
+ Project.all
+ ActiveRecord::LogSubscriber.runtime += 100
+ end
end
include ActiveSupport::LogSubscriber::TestHelper
@@ -52,4 +63,19 @@ def test_runtime_reset_before_requests
assert_equal 2, @logger.logged(:info).size
assert_match(/\(Views: [\d.]+ms \| ActiveRecord: 0.0ms\)/, @logger.logged(:info)[1])
end
+
+ def test_log_with_active_record_when_redirecting
+ get :redirect
+ wait
+ assert_equal 3, @logger.logged(:info).size
+ assert_match(/\(ActiveRecord: [\d.]+ms\)/, @logger.logged(:info)[2])
+ end
+
+ def test_include_time_query_time_after_rendering
+ get :db_after_render
+ wait
+
+ assert_equal 2, @logger.logged(:info).size
+ assert_match(/\(Views: [\d.]+ms \| ActiveRecord: ([1-9][\d.]+)ms\)/, @logger.logged(:info)[1])
+ end
end
View
4 activerecord/lib/active_record/railties/controller_runtime.rb
@@ -32,7 +32,9 @@ def cleanup_view_runtime
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

0 comments on commit 8a722e0

Please sign in to comment.
Something went wrong with that request. Please try again.