diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-11-05 10:59:50 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-11-05 11:05:16 -0700 |
commit | 8fee923888192a658d8823b31e77ed0683dfd665 (patch) | |
tree | 27b28c9971a98e770e1a14c4be46174754f0f6d7 /activerecord/lib/active_record/inheritance.rb | |
parent | 00ae750b23f0f9f59fd7058fc3bff043d2a04c5f (diff) | |
download | rails-8fee923888192a658d8823b31e77ed0683dfd665.tar.gz rails-8fee923888192a658d8823b31e77ed0683dfd665.tar.bz2 rails-8fee923888192a658d8823b31e77ed0683dfd665.zip |
Improve performance of AR object instantiation
We introduced a performance hit by adding an additional iteration
through a model's attributes on creation. We don't actually need the
values from `Result` to be a hash, we can separate the columns and
values and zip them up ourself during the iteration that we have to do.
Diffstat (limited to 'activerecord/lib/active_record/inheritance.rb')
-rw-r--r-- | activerecord/lib/active_record/inheritance.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb index f58145ab05..4aad3217cb 100644 --- a/activerecord/lib/active_record/inheritance.rb +++ b/activerecord/lib/active_record/inheritance.rb @@ -165,15 +165,19 @@ module ActiveRecord # record instance. For single-table inheritance, we check the record # for a +type+ column and return the corresponding class. def discriminate_class_for_record(record) - if using_single_table_inheritance?(record) - find_sti_class(record[inheritance_column]) + discriminate_class_for_value(record[inheritance_column]) + end + + def discriminate_class_for_value(value) + if using_single_table_inheritance?(value) + find_sti_class(value) else super end end - def using_single_table_inheritance?(record) - record[inheritance_column].present? && columns_hash.include?(inheritance_column) + def using_single_table_inheritance?(value) + value.present? && columns_hash.include?(inheritance_column) end def find_sti_class(type_name) |