diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-11-18 13:40:03 -0800 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-11-18 13:41:20 -0800 |
commit | 52fddcc653458456f98b3683dffd781cf00b35fe (patch) | |
tree | 7e78f34da766b2959e926a07f7f9672567c19241 /activerecord | |
parent | 1b9e85dbbd7d974143e67affb3166d7244cc99db (diff) | |
download | rails-52fddcc653458456f98b3683dffd781cf00b35fe.tar.gz rails-52fddcc653458456f98b3683dffd781cf00b35fe.tar.bz2 rails-52fddcc653458456f98b3683dffd781cf00b35fe.zip |
Speed up integer casting from DB
We don't have the check the range when the value is coming from the DB,
so override type_cast_from_database to short-circuit the extra work.
The difference is huge but the absolute gain is quite small. That being
said this is a hotspot and it showed up on the radar when benchmarking
discourse.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/type/integer.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/type/integer.rb b/activerecord/lib/active_record/type/integer.rb index d69e5b3f28..36bbd9cd5e 100644 --- a/activerecord/lib/active_record/type/integer.rb +++ b/activerecord/lib/active_record/type/integer.rb @@ -14,6 +14,11 @@ module ActiveRecord alias type_cast_for_database type_cast + def type_cast_from_database(value) + return if value.nil? + value.to_i + end + protected attr_reader :range |