Disable query cache for lock queries

Fixes #867
This commit is contained in:
Damir Zekic 2012-07-06 13:03:49 +02:00
parent 8ce61a3664
commit 75b340d1a4
2 changed files with 17 additions and 1 deletions

View File

@ -56,7 +56,7 @@ module ActiveRecord
end
def select_all(arel, name = nil, binds = [])
if @query_cache_enabled
if @query_cache_enabled && !locked?(arel)
sql = to_sql(arel, binds)
cache_sql(sql, binds) { super(sql, name, binds) }
else
@ -83,6 +83,14 @@ module ActiveRecord
result.collect { |row| row.dup }
end
end
def locked?(arel)
if arel.respond_to?(:locked)
arel.locked
else
false
end
end
end
end
end

View File

@ -164,6 +164,14 @@ class QueryCacheTest < ActiveRecord::TestCase
end
end
end
def test_cache_is_ignored_for_locked_relations
task = Task.find 1
Task.cache do
assert_queries(2) { task.lock!; task.lock! }
end
end
end
class QueryCacheExpiryTest < ActiveRecord::TestCase