From fbe586497b19b99dd7de8866ccaeb33b10e906c7 Mon Sep 17 00:00:00 2001 From: Andy Zhao Date: Fri, 7 Dec 2018 10:16:46 -0500 Subject: [PATCH] Synchronously bust cache after save for comments (#1275) --- app/models/comment.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 698d338e3..fccae0ad2 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -20,6 +20,7 @@ class Comment < ApplicationRecord after_create :after_create_checks after_save :calculate_score after_save :bust_cache + after_save :synchronous_bust before_destroy :before_destroy_actions after_create :send_email_notification, if: :should_send_email_notification? after_create :create_first_reaction @@ -292,11 +293,15 @@ class Comment < ApplicationRecord Comment.comment_async_bust(commentable, user.username) expire_root_fragment cache_buster = CacheBuster.new - cache_buster.bust(commentable.path.to_s) if commentable cache_buster.bust("#{commentable.path}/comments") if commentable end handle_asynchronously :bust_cache + def synchronous_bust + cache_buster = CacheBuster.new + cache_buster.bust(commentable.path.to_s) if commentable + end + def send_email_notification NotifyMailer.new_reply_email(self).deliver end