aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-01-03 04:42:56 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-01-03 04:42:56 +0900
commit059a476c570bc3451df855b99724e74bc2cba604 (patch)
tree8e4c188105149b276f24de389c967827a20b4f70 /activerecord
parent77ff9a0adbd1318b45203a76c64561b115245603 (diff)
downloadrails-059a476c570bc3451df855b99724e74bc2cba604.tar.gz
rails-059a476c570bc3451df855b99724e74bc2cba604.tar.bz2
rails-059a476c570bc3451df855b99724e74bc2cba604.zip
Counter cache touching don't need object finding anymore
`current_time_from_proper_timezone` and timestamp attributes methods was pushed up to class method.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/counter_cache.rb11
1 files changed, 5 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index f4ee008a12..93b9371206 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -46,7 +46,7 @@ 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
+ updates.merge!(touch_updates(touch)) if touch
unscoped.where(primary_key => object.id).update_all(updates)
end
@@ -105,8 +105,7 @@ module ActiveRecord
end
if touch
- object = find(id.is_a?(Array) ? id.first : id)
- updates << object.class.send(:sanitize_sql_for_assignment, touch_updates(object, touch))
+ updates << sanitize_sql_for_assignment(touch_updates(touch))
end
unscoped.where(primary_key => id).update_all updates.join(", ")
@@ -165,9 +164,9 @@ module ActiveRecord
end
private
- def touch_updates(object, touch)
- touch = object.send(:timestamp_attributes_for_update_in_model) if touch == true
- touch_time = object.send(:current_time_from_proper_timezone)
+ def touch_updates(touch)
+ touch = timestamp_attributes_for_update_in_model if touch == true
+ touch_time = current_time_from_proper_timezone
Array(touch).map { |column| [ column, touch_time ] }.to_h
end
end