diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-01-02 04:56:55 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-01-02 04:56:55 +0900 |
commit | 04a120fd94a75e2b8c7b5a79f42e3a4a9311931a (patch) | |
tree | 3df4537b9317f9deb4cf3157f827229ea36dd1af | |
parent | dae525eec8062bfbbe39141de448053b127d4756 (diff) | |
download | rails-04a120fd94a75e2b8c7b5a79f42e3a4a9311931a.tar.gz rails-04a120fd94a75e2b8c7b5a79f42e3a4a9311931a.tar.bz2 rails-04a120fd94a75e2b8c7b5a79f42e3a4a9311931a.zip |
Don't invoke `touch_updates` if `touch` does not supplied
`touch_updates` calls `Time.now` via `current_time_from_proper_timezone`
so it is better to not invoke `touch_updates` if it is unnecessary.
-rw-r--r-- | activerecord/lib/active_record/counter_cache.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb index 9355a2f7a7..3e637ad2b2 100644 --- a/activerecord/lib/active_record/counter_cache.rb +++ b/activerecord/lib/active_record/counter_cache.rb @@ -46,11 +46,11 @@ module ActiveRecord counter_name = reflection.counter_cache_column updates = { counter_name.to_sym => object.send(counter_association).count(:all) } + updates.merge!(touch_updates(object, touch)) if touch - unscoped.where(primary_key => object.id).update_all( - updates.merge(touch_updates(object, touch)) - ) + unscoped.where(primary_key => object.id).update_all(updates) end + return true end |