aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
authorRafael França <rafael@franca.dev>2019-07-24 15:31:17 -0400
committerGitHub <noreply@github.com>2019-07-24 15:31:17 -0400
commit01a28f3e6bf9f1550aca9b86b8805051c97a14d6 (patch)
treec8638658919d260663dbd7885696ceff3b1a1e5a /activerecord/lib/active_record/connection_adapters
parent5f774ac4585007dc46b5ae5f7ca11d4870c0d5ce (diff)
parentfc41373e242af3d6cfa27005a106192b54123f1e (diff)
downloadrails-01a28f3e6bf9f1550aca9b86b8805051c97a14d6.tar.gz
rails-01a28f3e6bf9f1550aca9b86b8805051c97a14d6.tar.bz2
rails-01a28f3e6bf9f1550aca9b86b8805051c97a14d6.zip
Merge pull request #36580 from Shopify/schema-cache-deuplication-from-database
Also deduplicate schema cache structure when they are read from the database
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r--activerecord/lib/active_record/connection_adapters/schema_cache.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/schema_cache.rb b/activerecord/lib/active_record/connection_adapters/schema_cache.rb
index 7d54fcf9a0..5e30304864 100644
--- a/activerecord/lib/active_record/connection_adapters/schema_cache.rb
+++ b/activerecord/lib/active_record/connection_adapters/schema_cache.rb
@@ -46,7 +46,11 @@ module ActiveRecord
end
def primary_keys(table_name)
- @primary_keys[table_name] ||= data_source_exists?(table_name) ? connection.primary_key(table_name) : nil
+ @primary_keys.fetch(table_name) do
+ if data_source_exists?(table_name)
+ @primary_keys[deep_deduplicate(table_name)] = deep_deduplicate(connection.primary_key(table_name))
+ end
+ end
end
# A cached lookup for table existence.
@@ -54,7 +58,7 @@ module ActiveRecord
prepare_data_sources if @data_sources.empty?
return @data_sources[name] if @data_sources.key? name
- @data_sources[name] = connection.data_source_exists?(name)
+ @data_sources[deep_deduplicate(name)] = connection.data_source_exists?(name)
end
# Add internal cache for table with +table_name+.
@@ -73,13 +77,17 @@ module ActiveRecord
# Get the columns for a table
def columns(table_name)
- @columns[table_name] ||= connection.columns(table_name)
+ @columns.fetch(table_name) do
+ @columns[deep_deduplicate(table_name)] = deep_deduplicate(connection.columns(table_name))
+ end
end
# 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] ||= columns(table_name).index_by(&:name)
+ @columns_hash.fetch(table_name) do
+ @columns_hash[deep_deduplicate(table_name)] = columns(table_name).index_by(&:name)
+ end
end
# Checks whether the columns hash is already cached for a table.
@@ -88,7 +96,9 @@ module ActiveRecord
end
def indexes(table_name)
- @indexes[table_name] ||= connection.indexes(table_name)
+ @indexes.fetch(table_name) do
+ @indexes[deep_deduplicate(table_name)] = deep_deduplicate(connection.indexes(table_name))
+ end
end
def database_version # :nodoc: