diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-14 10:16:27 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-14 10:16:27 -0700 |
commit | a1e2db2e9bb4ca2fdf6190aa8f448fe85cf76529 (patch) | |
tree | 15cae59a1040462eab651c52e30c5b25f59aed7a /activerecord/lib/active_record/counter_cache.rb | |
parent | 3bf8f8b05557c5661c9816f106c582fed1f10754 (diff) | |
parent | 655a3667aa99ae3f7e68024b3971b5783d6396bf (diff) | |
download | rails-a1e2db2e9bb4ca2fdf6190aa8f448fe85cf76529.tar.gz rails-a1e2db2e9bb4ca2fdf6190aa8f448fe85cf76529.tar.bz2 rails-a1e2db2e9bb4ca2fdf6190aa8f448fe85cf76529.zip |
Merge pull request #14735 from byroot/idempotent-counter-caches
Idempotent counter caches, fix concurrency issues with counter caches
Diffstat (limited to 'activerecord/lib/active_record/counter_cache.rb')
-rw-r--r-- | activerecord/lib/active_record/counter_cache.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb index dcbdf75627..a5897edf03 100644 --- a/activerecord/lib/active_record/counter_cache.rb +++ b/activerecord/lib/active_record/counter_cache.rb @@ -118,5 +118,26 @@ module ActiveRecord update_counters(id, counter_name => -1) end end + + protected + + def actually_destroyed? + @_actually_destroyed + end + + def clear_destroy_state + @_actually_destroyed = nil + end + + private + + def destroy_row + affected_rows = super + + @_actually_destroyed = affected_rows > 0 + + affected_rows + end + end end |