diff options
author | José Valim <jose.valim@gmail.com> | 2010-07-26 19:14:24 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-26 19:14:56 +0200 |
commit | dd61a817dea85990f13664d74bca15bc5796b76e (patch) | |
tree | 6ba9c03834a6aed9e2a691208a9c2ce6472aa92d /activerecord/lib | |
parent | 32844cbc025b394ecd0b9fe2fd755b4e5b6cd4e7 (diff) | |
download | rails-dd61a817dea85990f13664d74bca15bc5796b76e.tar.gz rails-dd61a817dea85990f13664d74bca15bc5796b76e.tar.bz2 rails-dd61a817dea85990f13664d74bca15bc5796b76e.zip |
Move runtime back to the Thread.current
Diffstat (limited to 'activerecord/lib')
3 files changed, 17 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index 69a963c3d3..d8c92d0ad3 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 = {} @instrumenter = ActiveSupport::Notifications.instrumenter @@ -92,11 +90,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 f7ae5587ed..c7ae12977a 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -1,13 +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"] ||= 0 + end + + def self.reset_runtime + rt, self.runtime = runtime, 0 + rt + end + def initialize super @odd_or_even = false end def sql(event) - connection = ActiveRecord::Base.connection - connection.runtime += event.duration + self.class.runtime += event.duration return unless logger.debug? name = '%s (%.1fms)' % [event.payload[:name], event.duration] @@ -33,4 +45,4 @@ module ActiveRecord end end -ActiveRecord::LogSubscriber.attach_to :active_record +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 cf74fa1655..bc6ca936c0 100644 --- a/activerecord/lib/active_record/railties/controller_runtime.rb +++ b/activerecord/lib/active_record/railties/controller_runtime.rb @@ -11,10 +11,9 @@ module ActiveRecord def cleanup_view_runtime if ActiveRecord::Base.connected? - connection = ActiveRecord::Base.connection - db_rt_before_render = connection.reset_runtime + db_rt_before_render = ActiveRecord::LogSubscriber.reset_runtime runtime = super - db_rt_after_render = 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 |