提交 8aead812 编写于 作者: T tsukasaoishi

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.
上级 9a0e0594
......@@ -19,6 +19,7 @@ def primary_keys(table_name)
# 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 @@ def marshal_dump
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册