FIX: mutex to avoid race condition with double notify

This commit is contained in:
Sam 2017-05-26 17:04:40 -04:00
parent 81c18fc0bd
commit a7e65d98a9

View File

@ -1,3 +1,5 @@
require_dependency 'distributed_mutex'
class PostAlerter
def self.post_created(post)
@ -222,6 +224,7 @@ class PostAlerter
notification_type = Notification.types[:group_message_summary]
DistributedMutex.synchronize("group_message_notify_#{user.id}") do
Notification.where(notification_type: notification_type, user_id: user.id).each do |n|
n.destroy if n.data_hash[:group_id] == stat[:group_id]
end
@ -236,6 +239,7 @@ class PostAlerter
username: user.username_lower
}.to_json
)
end
# TODO decide if it makes sense to also publish a desktop notification
end