diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-06 07:07:46 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-07-06 07:07:46 -0700 |
commit | 717aa92dd3f75dec04652940d5571ab34a2f79c3 (patch) | |
tree | e1b6d044ee68f5283420fb66c2598afad27de6c7 | |
parent | 48fe38201d2b56aa762282c741f5ebbbd99f23a4 (diff) | |
parent | 75b340d1a4bcf2f1233fb65a15ff6b8059e2230e (diff) | |
download | rails-717aa92dd3f75dec04652940d5571ab34a2f79c3.tar.gz rails-717aa92dd3f75dec04652940d5571ab34a2f79c3.tar.bz2 rails-717aa92dd3f75dec04652940d5571ab34a2f79c3.zip |
Merge pull request #6985 from sidonath/disable-query-cache-for-locks
Disable query cache for lock queries
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb | 10 | ||||
-rw-r--r-- | activerecord/test/cases/query_cache_test.rb | 8 |
2 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb index 3b4537aab4..a6e16da730 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb @@ -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 diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index 08f655d7fa..0153e74604 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -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 |