FIX: Destroy notifications and sync notifications count in transaction.

* Seeing errors where the user is destroyed right when the call to
  reload is made.
This commit is contained in:
Guo Xiang Tan 2018-05-25 12:00:13 +08:00
parent 755b511b5c
commit 9d307a9977

View File

@ -178,13 +178,15 @@ class PostAlerter
return if user.blank? return if user.blank?
return unless Guardian.new(user).can_see?(topic) return unless Guardian.new(user).can_see?(topic)
user.notifications.where( User.transaction do
notification_type: types, user.notifications.where(
topic_id: topic.id notification_type: types,
).destroy_all topic_id: topic.id
).destroy_all
# HACK so notification counts sync up correctly # Reload so notification counts sync up correctly
user.reload user.reload
end
end end
NOTIFIABLE_TYPES = [:mentioned, :replied, :quoted, :posted, :linked, :private_message, :group_mentioned].map { |t| NOTIFIABLE_TYPES = [:mentioned, :replied, :quoted, :posted, :linked, :private_message, :group_mentioned].map { |t|