diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-06-29 12:02:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-29 12:02:55 -0400 |
commit | 9c2ad53beff12cdc7b30dcfaa9d44eda38f7c68c (patch) | |
tree | e67daafb5fefb308ea6663867e6632dee7ec5df1 /activerecord | |
parent | 47c74e3dfe4e2532f9a4bc631b73b03fd7623fb8 (diff) | |
parent | abbc8351cd19f676476242bd6a0836b83dc3f0f0 (diff) | |
download | rails-9c2ad53beff12cdc7b30dcfaa9d44eda38f7c68c.tar.gz rails-9c2ad53beff12cdc7b30dcfaa9d44eda38f7c68c.tar.bz2 rails-9c2ad53beff12cdc7b30dcfaa9d44eda38f7c68c.zip |
Merge pull request #29623 from kamipo/should_use_same_connection_in_query_cache
Should use the same connection in using query cache
Diffstat (limited to 'activerecord')
3 files changed, 5 insertions, 11 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 33695c0537..c352ddfc11 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb @@ -108,6 +108,7 @@ module ActiveRecord "sql.active_record", sql: sql, binds: binds, + type_casted_binds: -> { type_casted_binds(binds) }, name: name, connection_id: object_id, cached: true, diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb index 2297c77835..e39ca5f6dc 100644 --- a/activerecord/lib/active_record/log_subscriber.rb +++ b/activerecord/lib/active_record/log_subscriber.rb @@ -29,7 +29,7 @@ module ActiveRecord binds = nil unless (payload[:binds] || []).empty? - casted_params = type_casted_binds(payload[:binds], payload[:type_casted_binds]) + casted_params = type_casted_binds(payload[:type_casted_binds]) binds = " " + payload[:binds].zip(casted_params).map { |attr, value| render_bind(attr, value) }.inspect @@ -42,9 +42,8 @@ module ActiveRecord end private - - def type_casted_binds(binds, casted_binds) - casted_binds || ActiveRecord::Base.connection.type_casted_binds(binds) + def type_casted_binds(casted_binds) + casted_binds.respond_to?(:call) ? casted_binds.call : casted_binds end def render_bind(attr, value) diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index 68d18e6471..b018a7b6c0 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -323,6 +323,7 @@ class QueryCacheTest < ActiveRecord::TestCase end def test_cache_is_available_when_using_a_not_connected_connection + skip "In-Memory DB can't test for using a not connected connection" if in_memory_db? with_temporary_connection_pool do spec_name = Task.connection_specification_name conf = ActiveRecord::Base.configurations["arunit"].merge("name" => "test2") @@ -332,13 +333,6 @@ class QueryCacheTest < ActiveRecord::TestCase Task.cache do begin - if in_memory_db? - Task.connection.create_table :tasks do |t| - t.datetime :starting - t.datetime :ending - end - ActiveRecord::FixtureSet.create_fixtures(self.class.fixture_path, ["tasks"], {}, ActiveRecord::Base) - end assert_queries(1) { Task.find(1); Task.find(1) } ensure ActiveRecord::Base.connection_handler.remove_connection(Task.connection_specification_name) |