Skip to content
This repository
Browse code

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 authored July 06, 2012
10  activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb
@@ -56,7 +56,7 @@ def clear_query_cache
56 56
       end
57 57
 
58 58
       def select_all(arel, name = nil, binds = [])
59  
-        if @query_cache_enabled
  59
+        if @query_cache_enabled && !locked?(arel)
60 60
           sql = to_sql(arel, binds)
61 61
           cache_sql(sql, binds) { super(sql, name, binds) }
62 62
         else
@@ -77,6 +77,14 @@ def cache_sql(sql, binds)
77 77
 
78 78
           result.collect { |row| row.dup }
79 79
         end
  80
+
  81
+        def locked?(arel)
  82
+          if arel.respond_to?(:locked)
  83
+            arel.locked
  84
+          else
  85
+            false
  86
+          end
  87
+        end
80 88
     end
81 89
   end
82 90
 end
8  activerecord/test/cases/query_cache_test.rb
@@ -165,6 +165,14 @@ def test_cache_does_not_wrap_string_results_in_arrays
165 165
       end
166 166
     end
167 167
   end
  168
+
  169
+  def test_cache_is_ignored_for_locked_relations
  170
+    task = Task.find 1
  171
+
  172
+    Task.cache do
  173
+      assert_queries(2) { task.lock!; task.lock! }
  174
+    end
  175
+  end
168 176
 end
169 177
 
170 178
 class QueryCacheExpiryTest < ActiveRecord::TestCase

0 notes on commit 7adc4f2

Please sign in to comment.
Something went wrong with that request. Please try again.