aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authortsukasaoishi <tsukasa.oishi@gmail.com>2014-08-07 22:41:23 +0900
committertsukasaoishi <tsukasa.oishi@gmail.com>2014-08-07 22:41:23 +0900
commit8aead812baaacb962c15d0ab27bdaf4c388b7d59 (patch)
treebf078e1343d46d846770809a300452cafccb5b92 /activerecord
parent9a0e0594ab919b5b1a3a85bbe90f4a44922b1d84 (diff)
downloadrails-8aead812baaacb962c15d0ab27bdaf4c388b7d59.tar.gz
rails-8aead812baaacb962c15d0ab27bdaf4c388b7d59.tar.bz2
rails-8aead812baaacb962c15d0ab27bdaf4c388b7d59.zip
Tables existence check query is executed in large quantities
When Rails starts, tables existence check query is executed number of models. In case of mysql, SHOW TABLES LIKE 'table1'; SHOW TABLES LIKE 'table2'; SHOW TABLES LIKE 'table3'; ... SHOW TABLES LIKE 'table999'; Add process to get the names of all tables by one query.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/schema_cache.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/schema_cache.rb b/activerecord/lib/active_record/connection_adapters/schema_cache.rb
index 3116bed596..726810535d 100644
--- a/activerecord/lib/active_record/connection_adapters/schema_cache.rb
+++ b/activerecord/lib/active_record/connection_adapters/schema_cache.rb
@@ -19,6 +19,7 @@ module ActiveRecord
# A cached lookup for table existence.
def table_exists?(name)
+ prepare_tables if @tables.blank?
return @tables[name] if @tables.key? name
@tables[name] = connection.table_exists?(name)
@@ -82,6 +83,12 @@ module ActiveRecord
def marshal_load(array)
@version, @columns, @columns_hash, @primary_keys, @tables = array
end
+
+ private
+
+ def prepare_tables
+ connection.tables.each { |table| @tables[table] = true }
+ end
end
end
end