diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-25 22:49:48 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-11-25 22:49:48 -0800 |
commit | c99e34e90d763c52cbe8dc3d950ed1b4db665dc4 (patch) | |
tree | 67a7b07a215073ad0b4c36c5cb1f6b406a66da04 /activerecord | |
parent | 4d0dc53249aefc75a7d258e256b268198a7dd7a1 (diff) | |
download | rails-c99e34e90d763c52cbe8dc3d950ed1b4db665dc4.tar.gz rails-c99e34e90d763c52cbe8dc3d950ed1b4db665dc4.tar.bz2 rails-c99e34e90d763c52cbe8dc3d950ed1b4db665dc4.zip |
speed up fixture loading by querying the schema cache for column names
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/schema_cache.rb | 11 |
2 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 4f3eebce7d..589e91c845 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -287,7 +287,7 @@ module ActiveRecord # Inserts the given fixture into the table. Overridden in adapters that require # something beyond a simple insert (eg. Oracle). def insert_fixture(fixture, table_name) - columns = Hash[columns(table_name).map { |c| [c.name, c] }] + columns = Hash[schema_cache.columns(table_name).map { |c| [c.name, c] }] key_list = [] value_list = fixture.map do |name, value| diff --git a/activerecord/lib/active_record/connection_adapters/schema_cache.rb b/activerecord/lib/active_record/connection_adapters/schema_cache.rb index aad1f9a7ef..c75dbfc082 100644 --- a/activerecord/lib/active_record/connection_adapters/schema_cache.rb +++ b/activerecord/lib/active_record/connection_adapters/schema_cache.rb @@ -1,7 +1,7 @@ module ActiveRecord module ConnectionAdapters class SchemaCache - attr_reader :columns, :columns_hash, :primary_keys, :tables, :version + attr_reader :columns_hash, :primary_keys, :tables, :version attr_accessor :connection def initialize(conn) @@ -30,6 +30,15 @@ module ActiveRecord end end + # Get the columns for a table + def columns(table = nil) + if table + @columns[table] + else + @columns + end + end + # Clears out internal caches def clear! @columns.clear |