Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rails/rails
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Oct 7, 2011
2 parents b1c20e3 + ea341b8 commit 9312d21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Expand Up @@ -314,7 +314,7 @@ def new_connection
end end


def current_connection_id #:nodoc: def current_connection_id #:nodoc:
Thread.current.object_id ActiveRecord::Base.connection_id ||= Thread.current.object_id
end end


def checkout_new_connection def checkout_new_connection
Expand Down
Expand Up @@ -115,6 +115,14 @@ def connection
retrieve_connection retrieve_connection
end 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: # Returns the configuration of the associated connection as a hash:
# #
# ActiveRecord::Base.connection_config # ActiveRecord::Base.connection_config
Expand Down
6 changes: 4 additions & 2 deletions activerecord/lib/active_record/query_cache.rb
Expand Up @@ -28,9 +28,10 @@ def initialize(app)
end end


class BodyProxy # :nodoc: class BodyProxy # :nodoc:
def initialize(original_cache_value, target) def initialize(original_cache_value, target, connection_id)
@original_cache_value = original_cache_value @original_cache_value = original_cache_value
@target = target @target = target
@connection_id = connection_id
end end


def method_missing(method_sym, *arguments, &block) def method_missing(method_sym, *arguments, &block)
Expand All @@ -48,6 +49,7 @@ def each(&block)
def close def close
@target.close if @target.respond_to?(:close) @target.close if @target.respond_to?(:close)
ensure ensure
ActiveRecord::Base.connection_id = @connection_id
ActiveRecord::Base.connection.clear_query_cache ActiveRecord::Base.connection.clear_query_cache
unless @original_cache_value unless @original_cache_value
ActiveRecord::Base.connection.disable_query_cache! ActiveRecord::Base.connection.disable_query_cache!
Expand All @@ -60,7 +62,7 @@ def call(env)
ActiveRecord::Base.connection.enable_query_cache! ActiveRecord::Base.connection.enable_query_cache!


status, headers, body = @app.call(env) 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 rescue Exception => e
ActiveRecord::Base.connection.clear_query_cache ActiveRecord::Base.connection.clear_query_cache
unless old unless old
Expand Down

0 comments on commit 9312d21

Please sign in to comment.