aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record.rb1
-rw-r--r--activerecord/lib/active_record/controller_runtime.rb27
-rw-r--r--activerecord/lib/active_record/rails.rb7
3 files changed, 33 insertions, 2 deletions
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index 196b87c0ac..2cfd528f2c 100644
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -52,6 +52,7 @@ module ActiveRecord
autoload :Batches
autoload :Calculations
autoload :Callbacks
+ autoload :ControllerRuntime
autoload :DynamicFinderMatch
autoload :DynamicScopeMatch
autoload :Migration
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
diff --git a/activerecord/lib/active_record/rails.rb b/activerecord/lib/active_record/rails.rb
index ddbc555113..8b22f869bc 100644
--- a/activerecord/lib/active_record/rails.rb
+++ b/activerecord/lib/active_record/rails.rb
@@ -7,6 +7,9 @@ require "action_controller/rails"
module ActiveRecord
class Plugin < Rails::Plugin
plugin_name :active_record
+ include_modules_in "ActiveRecord::Base"
+
+ config.action_controller.include "ActiveRecord::ControllerRuntime"
initializer "active_record.set_configs" do |app|
app.config.active_record.each do |k,v|
@@ -50,8 +53,8 @@ module ActiveRecord
initializer "active_record.notifications" do
require 'active_support/notifications'
- ActiveSupport::Notifications.subscribe("sql") do |name, before, after, result, instrumenter_id, payload|
- ActiveRecord::Base.connection.log_info(payload[:sql], name, after - before)
+ ActiveSupport::Notifications.subscribe("sql") do |name, before, after, instrumenter_id, payload|
+ ActiveRecord::Base.connection.log_info(payload[:sql], payload[:name], (after - before) * 1000)
end
end