diff options
author | José Valim <jose.valim@gmail.com> | 2010-07-25 16:42:05 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-25 16:42:05 +0200 |
commit | 82c7ef837d32897717b7c6e54cfa6f00d218a242 (patch) | |
tree | 9d1889930f769e13d818c7b7a8d792a854def9f1 /activerecord | |
parent | b1cfcedc8f6dde3b0855fc8fd564e72e730ba5cf (diff) | |
download | rails-82c7ef837d32897717b7c6e54cfa6f00d218a242.tar.gz rails-82c7ef837d32897717b7c6e54cfa6f00d218a242.tar.bz2 rails-82c7ef837d32897717b7c6e54cfa6f00d218a242.zip |
Move runtime to log subscriber.
Diffstat (limited to 'activerecord')
3 files changed, 18 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index c103fcccf7..c07ba2ac74 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -34,13 +34,11 @@ module ActiveRecord include QueryCache include ActiveSupport::Callbacks - attr_accessor :runtime define_callbacks :checkout, :checkin def initialize(connection, logger = nil) #:nodoc: @active = nil @connection, @logger = connection, logger - @runtime = 0 @query_cache_enabled = false @query_cache = {} end @@ -91,11 +89,6 @@ module ActiveRecord false end - def reset_runtime #:nodoc: - rt, @runtime = @runtime, 0 - rt - end - # QUOTING ================================================== # Override to return the quoted table name. Defaults to column quoting. diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index d7b99d796d..74b5893bfb 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -1,12 +1,25 @@ module ActiveRecord class LogSubscriber < ActiveSupport::LogSubscriber + def self.runtime=(value) + Thread.current["active_record_sql_runtime"] = value + end + + def self.runtime + Thread.current["active_record_sql_runtime"] + end + + def self.reset_runtime + rt, self.runtime = runtime, 0 + rt + end + def initialize super @odd_or_even = false end def sql(event) - connection.runtime += event.duration + self.class.runtime += event.duration return unless logger.debug? name = '%s (%.1fms)' % [event.payload[:name], event.duration] @@ -26,14 +39,11 @@ module ActiveRecord @odd_or_even = !@odd_or_even end - def connection - ActiveRecord::Base.connection - end - def logger ActiveRecord::Base.logger end end end -ActiveRecord::LogSubscriber.attach_to :active_record +ActiveRecord::LogSubscriber.runtime = 0 +ActiveRecord::LogSubscriber.attach_to :active_record
\ No newline at end of file diff --git a/activerecord/lib/active_record/railties/controller_runtime.rb b/activerecord/lib/active_record/railties/controller_runtime.rb index aed1c59b00..bc6ca936c0 100644 --- a/activerecord/lib/active_record/railties/controller_runtime.rb +++ b/activerecord/lib/active_record/railties/controller_runtime.rb @@ -11,9 +11,9 @@ module ActiveRecord def cleanup_view_runtime if ActiveRecord::Base.connected? - db_rt_before_render = ActiveRecord::Base.connection.reset_runtime + db_rt_before_render = ActiveRecord::LogSubscriber.reset_runtime runtime = super - db_rt_after_render = ActiveRecord::Base.connection.reset_runtime + db_rt_after_render = ActiveRecord::LogSubscriber.reset_runtime self.db_runtime = db_rt_before_render + db_rt_after_render runtime - db_rt_after_render else |