Refactor counter cache create and destroy#14765
Merged
rafaelfranca merged 5 commits intorails:masterfrom Apr 15, 2014
Merged
Conversation
Member
There was a problem hiding this comment.
Add # :nodoc: to remove this method from the public API
Member
|
Very good refactoring. I think this is a good direction to take. |
Member
Author
|
@rafaelfranca: I addressed both of your style concerns. And thanks :) |
Member
There was a problem hiding this comment.
# :nodoc: needs to be after the method name or it will remove all the documentation after it. Sorry for not being clear.
def decrement_counters # :nodoc:
Member
|
Could you squash your last two commits? The first four are fine to merge separately but the last two one are only review changes. |
rafaelfranca
added a commit
that referenced
this pull request
Apr 15, 2014
…nd-destroy Refactor counter cache create and destroy
Member
Author
|
@rafaelfranca I already did it 2 hours ago :p |
Member
|
Yes. When I commented the PR updated 😄 |
bquorning
added a commit
to zendesk/zombie_record
that referenced
this pull request
Aug 24, 2015
Previously we have just overridden the behavior of `ActiveRecord::Persistence#destroy_row` to apply soft-delete functionality. This does not work, since Rails depends on inheritance to add extra functionality to `#destroy_row`. In Rails 4.2, this includes `ActiveRecord::CounterCache#destroy_row` calling `super`, as well as `ActiveRecord::Locking::Optimistic#destroy_row` also calling `super`. See also rails/rails#14735 rails/rails#14765
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up of #14735
Move destroy and create counter cache callbacks code inside the
CounterCachemodel concern.The rationale is that the
after_destroycallback need to access theaffected_rowsvariable, and it's cleaner to be in the inheritance chain to access it than to leak it as yet another state on the model.This refactoring do not move the
updatepart of counter caches because Its way more complex and I prefer to do it in another PR.@tenderlove What do you think?
cc @arthurnn