mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Move runtime back to connection.
This commit is contained in:
parent
ff0d842454
commit
304c49b146
4 changed files with 15 additions and 21 deletions
|
@ -34,11 +34,13 @@ 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
|
||||
|
@ -89,6 +91,11 @@ 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.
|
||||
|
|
|
@ -1,25 +1,12 @@
|
|||
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)
|
||||
self.class.runtime += event.duration
|
||||
connection.runtime += event.duration
|
||||
return unless logger.debug?
|
||||
|
||||
name = '%s (%.1fms)' % [event.payload[:name], event.duration]
|
||||
|
@ -39,6 +26,10 @@ module ActiveRecord
|
|||
@odd_or_even = !@odd_or_even
|
||||
end
|
||||
|
||||
def connection
|
||||
ActiveRecord::Base.connection
|
||||
end
|
||||
|
||||
def logger
|
||||
ActiveRecord::Base.logger
|
||||
end
|
||||
|
|
|
@ -11,9 +11,9 @@ module ActiveRecord
|
|||
|
||||
def cleanup_view_runtime
|
||||
if ActiveRecord::Base.connected?
|
||||
db_rt_before_render = ActiveRecord::LogSubscriber.reset_runtime
|
||||
db_rt_before_render = ActiveRecord::Base.connection.reset_runtime
|
||||
runtime = super
|
||||
db_rt_after_render = ActiveRecord::LogSubscriber.reset_runtime
|
||||
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
|
||||
|
|
|
@ -57,8 +57,4 @@ class LogSubscriberTest < ActiveRecord::TestCase
|
|||
wait
|
||||
assert_equal 0, @logger.logged(:debug).size
|
||||
end
|
||||
|
||||
def test_initializes_runtime
|
||||
Thread.new { assert_equal 0, ActiveRecord::LogSubscriber.runtime }.join
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue