mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Merge branch 'master' of github.com:rails/rails
This commit is contained in:
@@ -314,7 +314,7 @@ module ActiveRecord
|
||||
end
|
||||
|
||||
def current_connection_id #:nodoc:
|
||||
Thread.current.object_id
|
||||
ActiveRecord::Base.connection_id ||= Thread.current.object_id
|
||||
end
|
||||
|
||||
def checkout_new_connection
|
||||
|
||||
@@ -115,6 +115,14 @@ module ActiveRecord
|
||||
retrieve_connection
|
||||
end
|
||||
|
||||
def connection_id
|
||||
Thread.current['ActiveRecord::Base.connection_id']
|
||||
end
|
||||
|
||||
def connection_id=(connection_id)
|
||||
Thread.current['ActiveRecord::Base.connection_id'] = connection_id
|
||||
end
|
||||
|
||||
# Returns the configuration of the associated connection as a hash:
|
||||
#
|
||||
# ActiveRecord::Base.connection_config
|
||||
|
||||
@@ -28,9 +28,10 @@ module ActiveRecord
|
||||
end
|
||||
|
||||
class BodyProxy # :nodoc:
|
||||
def initialize(original_cache_value, target)
|
||||
def initialize(original_cache_value, target, connection_id)
|
||||
@original_cache_value = original_cache_value
|
||||
@target = target
|
||||
@connection_id = connection_id
|
||||
end
|
||||
|
||||
def method_missing(method_sym, *arguments, &block)
|
||||
@@ -48,6 +49,7 @@ module ActiveRecord
|
||||
def close
|
||||
@target.close if @target.respond_to?(:close)
|
||||
ensure
|
||||
ActiveRecord::Base.connection_id = @connection_id
|
||||
ActiveRecord::Base.connection.clear_query_cache
|
||||
unless @original_cache_value
|
||||
ActiveRecord::Base.connection.disable_query_cache!
|
||||
@@ -60,7 +62,7 @@ module ActiveRecord
|
||||
ActiveRecord::Base.connection.enable_query_cache!
|
||||
|
||||
status, headers, body = @app.call(env)
|
||||
[status, headers, BodyProxy.new(old, body)]
|
||||
[status, headers, BodyProxy.new(old, body, ActiveRecord::Base.connection_id)]
|
||||
rescue Exception => e
|
||||
ActiveRecord::Base.connection.clear_query_cache
|
||||
unless old
|
||||
|
||||
Reference in New Issue
Block a user