Permalink
Browse files

speed up fixture loading by querying the schema cache for column names

  • Loading branch information...
1 parent 4d0dc53 commit c99e34e90d763c52cbe8dc3d950ed1b4db665dc4 @tenderlove tenderlove committed Nov 26, 2012
@@ -287,7 +287,7 @@ def reset_sequence!(table, column, sequence = nil)
# 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|
@@ -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 @@ def add(table_name)
end
end
+ # Get the columns for a table
+ def columns(table = nil)
+ if table
+ @columns[table]
+ else
+ @columns
+ end
+ end
@carlosantoniodasilva

carlosantoniodasilva Nov 26, 2012

Owner

Ok to keep this method around if the usage was changed later in dc973e7 to columns_hash?

+
# Clears out internal caches
def clear!
@columns.clear

0 comments on commit c99e34e

Please sign in to comment.