diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-26 16:51:54 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-31 10:59:50 -0800 |
commit | d6e41f364a73fb0378dc29d63c15ef7c18b8e18e (patch) | |
tree | 96d35a145ebfd4cd9e6b6c32cf36f4d634510cd9 /activerecord/lib/active_record/connection_adapters | |
parent | c091ab0207d949aeeeb4b28b949b7baa1e0631dc (diff) | |
download | rails-d6e41f364a73fb0378dc29d63c15ef7c18b8e18e.tar.gz rails-d6e41f364a73fb0378dc29d63c15ef7c18b8e18e.tar.bz2 rails-d6e41f364a73fb0378dc29d63c15ef7c18b8e18e.zip |
QueryCache will just dup an AR::Result, AR::Result can deep copy
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb | 24 |
1 files changed, 15 insertions, 9 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 52f09efd53..6ba64bb88f 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb @@ -65,18 +65,24 @@ module ActiveRecord end private - def cache_sql(sql, binds) - result = - if @query_cache[sql].key?(binds) - ActiveSupport::Notifications.instrument("sql.active_record", - :sql => sql, :binds => binds, :name => "CACHE", :connection_id => object_id) - @query_cache[sql][binds] - else - @query_cache[sql][binds] = yield - end + def cache_sql(sql, binds) + result = + if @query_cache[sql].key?(binds) + ActiveSupport::Notifications.instrument("sql.active_record", + :sql => sql, :binds => binds, :name => "CACHE", :connection_id => object_id) + @query_cache[sql][binds] + else + @query_cache[sql][binds] = yield + end + # FIXME: we should guarantee that all cached items are Result + # objects. Then we can avoid this conditional + if ActiveRecord::Result === result + result.dup + else result.collect { |row| row.dup } end + end end end end |