From bba7c63a663b073034f4c73f0d59655751694e5a Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Fri, 21 Jun 2019 12:11:16 +0200 Subject: Also deduplicate schema cache data when using the init_with interface --- .../lib/active_record/connection_adapters/schema_cache.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/schema_cache.rb b/activerecord/lib/active_record/connection_adapters/schema_cache.rb index 5da26171bb..d01327290d 100644 --- a/activerecord/lib/active_record/connection_adapters/schema_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/schema_cache.rb @@ -35,11 +35,11 @@ module ActiveRecord end def init_with(coder) - @columns = coder["columns"] - @columns_hash = {} - @primary_keys = coder["primary_keys"] - @data_sources = coder["data_sources"] - @indexes = coder["indexes"] || {} + @columns = deep_deduplicate(coder["columns"]) + @columns_hash = @columns.transform_values { |columns| columns.index_by(&:name) } + @primary_keys = deep_deduplicate(coder["primary_keys"]) + @data_sources = deep_deduplicate(coder["data_sources"]) + @indexes = deep_deduplicate(coder["indexes"] || {}) @version = coder["version"] @database_version = coder["database_version"] end @@ -127,9 +127,9 @@ module ActiveRecord def marshal_load(array) @version, @columns, _columns_hash, @primary_keys, @data_sources, @indexes, @database_version = array @indexes ||= {} - @columns_hash = {} @columns = deep_deduplicate(@columns) + @columns_hash = @columns.transform_values { |columns| columns.index_by(&:name) } @primary_keys = deep_deduplicate(@primary_keys) @data_sources = deep_deduplicate(@data_sources) @indexes = deep_deduplicate(@indexes) -- cgit v1.2.3