aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2007-02-21 21:54:41 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2007-02-21 21:54:41 +0000
commit7842caed942d5a410dcc0c22f2d3dfd808fa0cfa (patch)
tree4b23b287f9773be8beb5c304af531e354ee8aa92 /activerecord
parent2ffbc6115e5389642f1b1c10fa5257aef0ad3920 (diff)
downloadrails-7842caed942d5a410dcc0c22f2d3dfd808fa0cfa.tar.gz
rails-7842caed942d5a410dcc0c22f2d3dfd808fa0cfa.tar.bz2
rails-7842caed942d5a410dcc0c22f2d3dfd808fa0cfa.zip
Fixed query cache when multiple database connections were involved
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6195 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/query_cache.rb4
-rw-r--r--activerecord/test/query_cache_test.rb11
2 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb
index e5f3d7825c..e29c86d935 100644
--- a/activerecord/lib/active_record/query_cache.rb
+++ b/activerecord/lib/active_record/query_cache.rb
@@ -73,13 +73,13 @@ module ActiveRecord
alias_method :connection_without_query_cache, :connection
def query_caches
- (Thread.current[:query_cache] ||= {})
+ Thread.current["query_cache_#{connection_without_query_cache.object_id}"] ||= {}
end
def query_cache
if query_caches[self]
query_caches[self]
- elsif superclass.respond_to?(:query_cache)
+ elsif superclass.respond_to?(:query_cache) and superclass.respond_to?(:connection) and superclass.connection_without_query_cache == connection_without_query_cache
superclass.query_cache
end
end
diff --git a/activerecord/test/query_cache_test.rb b/activerecord/test/query_cache_test.rb
index 1ede03e70e..4cadc32316 100644
--- a/activerecord/test/query_cache_test.rb
+++ b/activerecord/test/query_cache_test.rb
@@ -2,6 +2,7 @@ require 'abstract_unit'
require 'fixtures/topic'
require 'fixtures/reply'
require 'fixtures/task'
+require 'fixtures/course'
class QueryCacheTest < Test::Unit::TestCase
fixtures :tasks
@@ -43,6 +44,16 @@ class QueryCacheTest < Test::Unit::TestCase
end
end
+ def test_cache_does_not_blow_up_other_connections
+ assert_not_equal Course.connection.object_id, Task.connection.object_id,
+ "Connections should be different, Course connects to a different database"
+
+ ActiveRecord::Base.cache do
+ assert_not_equal Course.connection.object_id, Task.connection.object_id,
+ "Connections should be different, Course connects to a different database"
+ end
+ end
+
end