diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2019-06-19 21:22:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-19 21:22:01 +0200 |
commit | 8a20a40fef066ef52571f0c30aee92dd0fa36e15 (patch) | |
tree | 6518c1f354a345d57d2763fac35087dc04e682f3 | |
parent | 75eb9494d897a30e41c63ee6ae266bb9b7c66140 (diff) | |
parent | dc99e5fe6529f3702b0490349cbc1f45c031a5c6 (diff) | |
download | rails-8a20a40fef066ef52571f0c30aee92dd0fa36e15.tar.gz rails-8a20a40fef066ef52571f0c30aee92dd0fa36e15.tar.bz2 rails-8a20a40fef066ef52571f0c30aee92dd0fa36e15.zip |
Merge pull request #36518 from Shopify/drop-schema-cache-column-hash
Stop serializing and parsing columns_hash in Active Record schema caches
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/schema_cache.rb | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/schema_cache.rb b/activerecord/lib/active_record/connection_adapters/schema_cache.rb index 218d6c168a..5da26171bb 100644 --- a/activerecord/lib/active_record/connection_adapters/schema_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/schema_cache.rb @@ -27,7 +27,6 @@ module ActiveRecord def encode_with(coder) coder["columns"] = @columns - coder["columns_hash"] = @columns_hash coder["primary_keys"] = @primary_keys coder["data_sources"] = @data_sources coder["indexes"] = @indexes @@ -37,7 +36,7 @@ module ActiveRecord def init_with(coder) @columns = coder["columns"] - @columns_hash = coder["columns_hash"] + @columns_hash = {} @primary_keys = coder["primary_keys"] @data_sources = coder["data_sources"] @indexes = coder["indexes"] || {} @@ -79,9 +78,7 @@ module ActiveRecord # Get the columns for a table as a hash, key is the column name # value is the column object. def columns_hash(table_name) - @columns_hash[table_name] ||= Hash[columns(table_name).map { |col| - [col.name, col] - }] + @columns_hash[table_name] ||= columns(table_name).index_by(&:name) end # Checks whether the columns hash is already cached for a table. @@ -124,15 +121,15 @@ module ActiveRecord def marshal_dump # if we get current version during initialization, it happens stack over flow. @version = connection.migration_context.current_version - [@version, @columns, @columns_hash, @primary_keys, @data_sources, @indexes, database_version] + [@version, @columns, {}, @primary_keys, @data_sources, @indexes, database_version] end def marshal_load(array) - @version, @columns, @columns_hash, @primary_keys, @data_sources, @indexes, @database_version = array + @version, @columns, _columns_hash, @primary_keys, @data_sources, @indexes, @database_version = array @indexes ||= {} + @columns_hash = {} @columns = deep_deduplicate(@columns) - @columns_hash = deep_deduplicate(@columns_hash) @primary_keys = deep_deduplicate(@primary_keys) @data_sources = deep_deduplicate(@data_sources) @indexes = deep_deduplicate(@indexes) |