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
Bust cache on article destroy instead of resave articles #1621 #1801
Conversation
| article_ids.concat organization.article_ids | ||
| end | ||
| # perform busting cache in chunks in case there're a lot of articles | ||
| (article_ids.uniq.sort - [id]).each_slice(10) do |ids| |
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.
Sorting here is just to be able to test, that the job is enqueued with the correct arguments (spec/models/article_destroy_spec.rb:24). The order of article_ids is not important. Sets are not allowed as job arguments.
If anyone has a better idea to remove sorting and still test, please, share.
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.
This looks good! After looking through RSpec's API docs, I couldn't find a better way to avoid sorting the array. I'm guessing it's not a huge performance issue, so it should be okay to sort the array.
What type of PR is this? (check all applicable)
Description
In the current implementation, when an article is destroyed, all the "sibling" articles of the (destroyed) article organization are resaved. Resaving triggers several callbacks, which create a lot of delayed_jobs. That takes plenty of time and resources. There's no need to resave articles, it's enough to bust their cache.
What happens on article destroy after the refactoring:
Related Tickets & Documents
#1621
Not directly related to the ticket (not fixing errors), but contains refactoring for the related code.