From 69600a9f97d2f678972500d8a741edc745833718 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 1 Feb 2011 10:37:53 -0800 Subject: avoid column lookup on subclasses, keep column info cached as table_name => column_list --- activerecord/lib/active_record/base.rb | 10 ++++++++-- activerecord/lib/active_record/session_store.rb | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 220d861a27..1e762a287d 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -671,7 +671,11 @@ module ActiveRecord #:nodoc: # 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 @@ module ActiveRecord #: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 @@ MSG quoted_value end end + @@columns_cache = {} public # New objects can be instantiated as either empty (pass no construction parameter) or pre-set with diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb index 3400fd6ade..68d9f89edd 100644 --- a/activerecord/lib/active_record/session_store.rb +++ b/activerecord/lib/active_record/session_store.rb @@ -59,10 +59,12 @@ module ActiveRecord 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 -- cgit v1.2.3