aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/counter_cache.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-01-02 04:56:55 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-01-02 04:56:55 +0900
commit04a120fd94a75e2b8c7b5a79f42e3a4a9311931a (patch)
tree3df4537b9317f9deb4cf3157f827229ea36dd1af /activerecord/lib/active_record/counter_cache.rb
parentdae525eec8062bfbbe39141de448053b127d4756 (diff)
downloadrails-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.
Diffstat (limited to 'activerecord/lib/active_record/counter_cache.rb')
-rw-r--r--activerecord/lib/active_record/counter_cache.rb6
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