From 18bf30982bb2ec013dc65a7e7e65ff45fcd4d73b Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Wed, 14 Dec 2011 15:58:43 +0000 Subject: Cache column defaults on model. ~30% on Model.new due to avoiding repeatedly fetching connection. --- activerecord/lib/active_record/base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index ba75dc6d09..9215a68cfc 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -782,7 +782,7 @@ module ActiveRecord #:nodoc: # Returns a hash where the keys are column names and the values are # default values when instantiating the AR object for this table. def column_defaults - connection.schema_cache.column_defaults[table_name] + @column_defaults ||= connection.schema_cache.column_defaults[table_name] end # Returns an array of column names as strings. @@ -841,7 +841,7 @@ module ActiveRecord #:nodoc: undefine_attribute_methods connection.schema_cache.clear_table_cache!(table_name) if table_exists? - @column_names = @content_columns = @dynamic_methods_hash = @inheritance_column = nil + @column_names = @content_columns = @column_defaults = @dynamic_methods_hash = @inheritance_column = nil @arel_engine = @relation = nil end -- cgit v1.2.3