Skip to content

Commit

Permalink
Merge pull request #6985 from sidonath/disable-query-cache-for-locks
Browse files Browse the repository at this point in the history
Disable query cache for lock queries
  • Loading branch information
rafaelfranca committed Jul 6, 2012
2 parents 48fe382 + 75b340d commit 717aa92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Expand Up @@ -56,7 +56,7 @@ def clear_query_cache
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
Expand All @@ -83,6 +83,14 @@ def cache_sql(sql, binds)
result.collect { |row| row.dup }
end
end

def locked?(arel)
if arel.respond_to?(:locked)
arel.locked
else
false
end
end
end
end
end
8 changes: 8 additions & 0 deletions activerecord/test/cases/query_cache_test.rb
Expand Up @@ -164,6 +164,14 @@ def test_cache_does_not_wrap_string_results_in_arrays
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
Expand Down

0 comments on commit 717aa92

Please sign in to comment.