[deploy] Skip updating a root comment if it doesnt exist (#7080)
This commit is contained in:
parent
fa89b163f7
commit
cbe6b3bd70
3 changed files with 11 additions and 2 deletions
|
|
@ -185,7 +185,11 @@ class Comment < ApplicationRecord
|
|||
end
|
||||
|
||||
def expire_root_fragment
|
||||
root.touch
|
||||
if root_exists?
|
||||
root.touch
|
||||
else
|
||||
touch
|
||||
end
|
||||
end
|
||||
|
||||
def create_first_reaction
|
||||
|
|
@ -214,6 +218,10 @@ class Comment < ApplicationRecord
|
|||
expire_root_fragment
|
||||
end
|
||||
|
||||
def root_exists?
|
||||
ancestry && Comment.exists?(id: ancestry)
|
||||
end
|
||||
|
||||
def send_email_notification
|
||||
Comments::SendEmailNotificationWorker.perform_async(id)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ module Comments
|
|||
spaminess_rating = BlackBox.calculate_spaminess(comment)
|
||||
|
||||
comment.update_columns(score: score, spaminess_rating: spaminess_rating)
|
||||
comment.root.save! unless comment.is_root?
|
||||
comment.root.save! if !comment.is_root? && comment.root_exists?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ RSpec.describe Comments::CalculateScoreWorker, type: :worker do
|
|||
allow(root_comment).to receive(:save!)
|
||||
allow(child_comment).to receive(:update_columns)
|
||||
allow(child_comment).to receive(:is_root?).and_return(false)
|
||||
allow(child_comment).to receive(:root_exists?).and_return(true)
|
||||
allow(child_comment).to receive(:root).and_return(root_comment)
|
||||
allow(Comment).to receive(:find_by).with(id: 1).and_return(child_comment)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue