提交 94cd08be 编写于 作者: A Aaron Patterson

extract cache counter logic to one method

上级 e2be6eac
......@@ -37,23 +37,22 @@ def find_target?
!loaded? && foreign_key_present? && klass
end
def update_counters(record)
def with_cache_name
counter_cache_name = reflection.counter_cache_column
return unless counter_cache_name && owner.persisted?
return unless different_target? record
record.class.increment_counter(counter_cache_name, record.id)
yield counter_cache_name
end
decrement_counter counter_cache_name
def update_counters(record)
with_cache_name do |name|
return unless different_target? record
record.class.increment_counter(name, record.id)
decrement_counter name
end
end
def decrement_counters
counter_cache_name = reflection.counter_cache_column
return unless counter_cache_name && owner.persisted?
decrement_counter counter_cache_name
with_cache_name { |name| decrement_counter name }
end
def decrement_counter counter_cache_name
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册