aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-11-18 15:19:15 -0800
committerSean Griffin <sean@thoughtbot.com>2014-11-18 15:20:19 -0800
commit08576b94ad4f19dfc368619d7751e211d23dcad8 (patch)
treea8be0f668e65f0c90a79cd3031984c507225019c /activerecord/lib/active_record/attribute_methods.rb
parent78e7a0d3b7eaafe1ad0a45e3e355e1123cae3f8b (diff)
downloadrails-08576b94ad4f19dfc368619d7751e211d23dcad8.tar.gz
rails-08576b94ad4f19dfc368619d7751e211d23dcad8.tar.bz2
rails-08576b94ad4f19dfc368619d7751e211d23dcad8.zip
Improve the performance of reading attributes
We added a comparison to "id", and call to `self.class.primary_key` a *lot*. We also have performance hits from `&block` all over the place. We skip the check in a new method, in order to avoid breaking the behavior of `read_attribute`
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 34ec397aee..d766996d37 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -332,7 +332,7 @@ module ActiveRecord
# task.attribute_present?(:title) # => true
# task.attribute_present?(:is_done) # => true
def attribute_present?(attribute)
- value = read_attribute(attribute)
+ value = _read_attribute(attribute)
!value.nil? && !(value.respond_to?(:empty?) && value.empty?)
end
@@ -433,7 +433,7 @@ module ActiveRecord
end
def typecasted_attribute_value(name)
- read_attribute(name)
+ _read_attribute(name)
end
end
end