aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/controller_runtime.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2009-12-27 14:44:21 -0800
committerDavid Heinemeier Hansson <david@loudthinking.com>2009-12-27 14:44:21 -0800
commit5012a1558dd1483df525f1fac1e649e089be886a (patch)
tree983136a50ee7bb135768038e33c9c226a3a167ed /activerecord/lib/active_record/controller_runtime.rb
parent1cd949006a419807d5ae3400442942b752780ca2 (diff)
parent12e43494a748e0144195be12dc19161cc3e4d39f (diff)
downloadrails-5012a1558dd1483df525f1fac1e649e089be886a.tar.gz
rails-5012a1558dd1483df525f1fac1e649e089be886a.tar.bz2
rails-5012a1558dd1483df525f1fac1e649e089be886a.zip
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'activerecord/lib/active_record/controller_runtime.rb')
-rw-r--r--activerecord/lib/active_record/controller_runtime.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/controller_runtime.rb b/activerecord/lib/active_record/controller_runtime.rb
new file mode 100644
index 0000000000..1281901ae8
--- /dev/null
+++ b/activerecord/lib/active_record/controller_runtime.rb
@@ -0,0 +1,27 @@
+module ActiveRecord
+ module ControllerRuntime
+ extend ActiveSupport::Concern
+
+ attr_internal :db_runtime
+
+ def cleanup_view_runtime
+ if Object.const_defined?("ActiveRecord") && ActiveRecord::Base.connected?
+ db_rt_before_render = ActiveRecord::Base.connection.reset_runtime
+ runtime = super
+ db_rt_after_render = ActiveRecord::Base.connection.reset_runtime
+ self.db_runtime = db_rt_before_render + db_rt_after_render
+ runtime - db_rt_after_render
+ else
+ super
+ end
+ end
+
+ module ClassMethods
+ def process_log_action(controller)
+ super
+ db_runtime = controller.send :db_runtime
+ logger.info(" ActiveRecord runtime: %.1fms" % db_runtime.to_f) if db_runtime
+ end
+ end
+ end
+end \ No newline at end of file