2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-04-08 21:53:23 -04:00
|
|
|
# perf fixes, review for each rails upgrade.
|
|
|
|
|
2019-01-26 00:25:37 -05:00
|
|
|
# This speeds up calls to present? and blank? on model instances
|
|
|
|
# Eg: Topic.new.blank? (which is always false) and so on.
|
|
|
|
#
|
|
|
|
# Per: https://gist.github.com/SamSaffron/c8bbc8c7b6bf3b0148760c887df18b55
|
|
|
|
# Comparison:
|
|
|
|
# fast present: 25253295.0 i/s
|
|
|
|
# fast present 2: 24623199.7 i/s - same-ish: difference falls within error
|
|
|
|
# slow present: 335003.0 i/s - 75.38x slower
|
|
|
|
# slow present 2: 275212.8 i/s - 91.76x slower
|
|
|
|
#
|
|
|
|
# raised with rails at: https://github.com/rails/rails/issues/35059
|
2013-04-24 00:40:55 -04:00
|
|
|
class ActiveRecord::Base
|
|
|
|
def present?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
def blank?
|
|
|
|
false
|
|
|
|
end
|
2015-04-24 13:10:43 -04:00
|
|
|
end
|