aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/query_cache.rb
diff options
context:
space:
mode:
authorMark J. Titorenko <mark@titorenko.net>2011-06-13 02:14:18 +0100
committerMark J. Titorenko <mark@titorenko.net>2011-10-07 10:05:51 +0100
commitf41b58d3b25eb57ba5c890b713301ba2e3fcb9b7 (patch)
treef07ff60695b4dea17355f8967e696682b5343b18 /activerecord/lib/active_record/query_cache.rb
parent3088d23647899212f20bb8969f2084393a9e71cd (diff)
downloadrails-f41b58d3b25eb57ba5c890b713301ba2e3fcb9b7.tar.gz
rails-f41b58d3b25eb57ba5c890b713301ba2e3fcb9b7.tar.bz2
rails-f41b58d3b25eb57ba5c890b713301ba2e3fcb9b7.zip
use thread locals and an instance variable within QueryCache#BodyProxy to maintain appropriate linkage with AR database connection across threads
Diffstat (limited to 'activerecord/lib/active_record/query_cache.rb')
-rw-r--r--activerecord/lib/active_record/query_cache.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb
index 10c0dc6f2a..466d148901 100644
--- a/activerecord/lib/active_record/query_cache.rb
+++ b/activerecord/lib/active_record/query_cache.rb
@@ -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