Skip to content

Commit

Permalink
speed up fixture loading by querying the schema cache for column names
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Nov 26, 2012
1 parent 4d0dc53 commit c99e34e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Expand Up @@ -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|
Expand Down
@@ -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)
Expand Down Expand Up @@ -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

This comment has been minimized.

Copy link
@carlosantoniodasilva

carlosantoniodasilva Nov 26, 2012

Member

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
Expand Down

0 comments on commit c99e34e

Please sign in to comment.