-
Notifications
You must be signed in to change notification settings - Fork 21.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make AR::Base#touch fire the after_commit and after_rollback callbacks #12031
Conversation
👍 |
def blocks | ||
@blocks ||= [] | ||
end | ||
def on_after_commit(&block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need one line before on_after_commit
method!
Please add Changelog |
@pftg updated, thanks for the feedback |
👍 |
Bump? |
We've been running this in production via a monkey patch for 4 months. Works as intended. |
Us at Shopify too |
Hey folks, sorry I missed this one, already marked it here to take a look as soon as I find some time here. Thanks! |
I think we wanna close this PR, and open another one against master... =( , than we backport if needed. |
@@ -1465,7 +1465,9 @@ def test_cache_key_changes_when_child_touched | |||
Bulb.create(car: car) | |||
|
|||
key = car.cache_key | |||
car.bulb.touch | |||
Bulb.transaction do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this necessary?
Make AR::Base#touch fire the after_commit and after_rollback callbacks. Closes #12031. Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/integration_test.rb
As of rails#12031 after_commit and after_rollback are also executed
I expected
to output "cache expired", but it doesn't, and it used to in Rails 3.0. This PR brings back that functionality by making touches call
after_commit
callbacks, woo!We relied on
after_commit
callbacks being fired by touches to do things like expire caches, send documents to our search cluster, bump versions in Redis, etc. When we upgraded to 3.2, we found this problem and had to go and addafter_touch
callbacks to all those places to get touches to cause the same changes in the system. We make pretty heavy use of touches to bump timestamps up the association chain and whatnot, so they are a principle instigator of attribute change in the system. I think having to add both callbacks to really get a callback fired when stuff changes is sucky because it means client code has to deal with de-duplication if both callbacks fire, client code has to be aware of the semantic differences of when they fire, and before this change there is no way to get called back to when a record's timestamp bump has definitely been committed to the database.Thanks for any feedback you can give me!
@carlosantoniodasilva this is a follow up to #12026 on top of
4-0-stable
, is this what you need?