aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/active_record_runtime.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-12-26 20:28:53 +0100
committerJosé Valim <jose.valim@gmail.com>2009-12-26 20:28:53 +0100
commit75ba102a80965b2612df0253d1278581a88b8d66 (patch)
tree435658d7914821be2e745bf3468139cf6a753a07 /actionpack/lib/action_controller/metal/active_record_runtime.rb
parent8a36e907d2a0a28be1fa8334221cc2e195d75168 (diff)
downloadrails-75ba102a80965b2612df0253d1278581a88b8d66.tar.gz
rails-75ba102a80965b2612df0253d1278581a88b8d66.tar.bz2
rails-75ba102a80965b2612df0253d1278581a88b8d66.zip
Remove ActionView inline logging to ActiveSupport::Notifications and create ActionController::Base#log_event, so everything can be logged within one listener. Also expose log_process_action as a hook for different modules to include their own information during the action processing. This allow ActiveRecord to hook and any other ORM. Finally, this commit changes 'Processing' and 'Rendering' in logs to 'Processed' and 'Rendered' because at the point it's logged, everying already happened.
Diffstat (limited to 'actionpack/lib/action_controller/metal/active_record_runtime.rb')
-rw-r--r--actionpack/lib/action_controller/metal/active_record_runtime.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/active_record_runtime.rb b/actionpack/lib/action_controller/metal/active_record_runtime.rb
new file mode 100644
index 0000000000..29f6dcc783
--- /dev/null
+++ b/actionpack/lib/action_controller/metal/active_record_runtime.rb
@@ -0,0 +1,27 @@
+module ActionController
+ module ActiveRecordRuntime
+ 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