From 04a120fd94a75e2b8c7b5a79f42e3a4a9311931a Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 2 Jan 2017 04:56:55 +0900 Subject: 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. --- activerecord/lib/active_record/counter_cache.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord') 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 -- cgit v1.2.3