提交 69600a9f 编写于 作者: A Aaron Patterson

avoid column lookup on subclasses, keep column info cached as table_name => column_list

上级 3cc2b77d
......@@ -671,7 +671,11 @@ def columns
# Returns a hash of column objects for the table associated with this class.
def columns_hash
@columns_hash ||= Hash[columns.map { |column| [column.name, column] }]
@@columns_cache[table_name] ||= Hash[columns.map { |column| [column.name, column] }]
end
def columns_hash=(value)
@@columns_cache[table_name] = value
end
# Returns an array of column names as strings.
......@@ -728,7 +732,8 @@ def column_methods_hash #:nodoc:
def reset_column_information
connection.clear_cache!
undefine_attribute_methods
@column_names = @columns = @columns_hash = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
self.columns_hash = nil
@column_names = @columns = @content_columns = @dynamic_methods_hash = @inheritance_column = nil
@arel_engine = @relation = @arel_table = nil
end
......@@ -1376,6 +1381,7 @@ def encode_quoted_value(value) #:nodoc:
quoted_value
end
end
@@columns_cache = {}
public
# New objects can be instantiated as either empty (pass no construction parameter) or pre-set with
......
......@@ -59,10 +59,12 @@ def unmarshal(data)
end
def drop_table!
self.columns_hash = nil
connection.drop_table table_name
end
def create_table!
self.columns_hash = nil
connection.create_table(table_name) do |t|
t.string session_id_column, :limit => 255
t.text data_column_name
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册