Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #6985 from sidonath/disable-query-cache-for-locks

Disable query cache for lock queries
Conflicts:
	activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
  • Loading branch information...
commit 7adc4f20cc78f1150640bdc0a60832b3752244dc 1 parent 03dcdc3
Rafael Mendonça França rafaelfranca authored
10 activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
View
@@ -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
@@ -77,6 +77,14 @@ def cache_sql(sql, binds)
result.collect { |row| row.dup }
end
+
+ def locked?(arel)
+ if arel.respond_to?(:locked)
+ arel.locked
+ else
+ false
+ end
+ end
end
end
end
8 activerecord/test/cases/query_cache_test.rb
View
@@ -165,6 +165,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
Please sign in to comment.
Something went wrong with that request. Please try again.