diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-27 14:05:40 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-27 14:05:40 -0700 |
commit | 7104122cc3fca4939d77a6780910cd98ff02fab0 (patch) | |
tree | c3244d33a0c7298a1befaaa8ac53de302394a11c /activerecord | |
parent | 47ceb135c6b75988f2712bc44db397b992c1c731 (diff) | |
download | rails-7104122cc3fca4939d77a6780910cd98ff02fab0.tar.gz rails-7104122cc3fca4939d77a6780910cd98ff02fab0.tar.bz2 rails-7104122cc3fca4939d77a6780910cd98ff02fab0.zip |
making query cache work with prepared statements
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb | 13 | ||||
-rw-r--r-- | activerecord/test/cases/query_cache_test.rb | 6 |
2 files changed, 13 insertions, 6 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 0ee61d0b6f..cbc09dfc3b 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb @@ -49,23 +49,24 @@ module ActiveRecord @query_cache.clear end - def select_all(*args) + def select_all(sql, name = nil, binds = []) if @query_cache_enabled - cache_sql(args.first) { super } + cache_sql(sql, binds) { super } else super end end private - def cache_sql(sql) + def cache_sql(sql, binds) + key = [sql, binds] result = - if @query_cache.has_key?(sql) + if @query_cache.has_key?(key) ActiveSupport::Notifications.instrument("sql.active_record", :sql => sql, :name => "CACHE", :connection_id => self.object_id) - @query_cache[sql] + @query_cache[key] else - @query_cache[sql] = yield + @query_cache[key] = yield end if Array === result diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index bdd0cc6b7b..fe2aa1ccf6 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -22,6 +22,12 @@ class QueryCacheTest < ActiveRecord::TestCase end end + def test_find_queries_with_cache + Task.cache do + assert_queries(2) { Task.find(1); Task.find(1); Task.find(2) } + end + end + def test_count_queries_with_cache Task.cache do assert_queries(1) { Task.count; Task.count } |