From 676c432b0faf3c7d6d51b40b6a0e806d685c44a1 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Wed, 23 Oct 2019 16:09:55 +1100 Subject: [PATCH] FIX: notifications are missing under certain conditions This simplifies the code for refreshing notification counts. It now unconditionally looks up the user object which protects against stale objects in memory. This also removes a pile of conditional logic we no longer need. --- app/models/notification.rb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 0d2a232b619..b39fc97ac03 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -217,15 +217,8 @@ class Notification < ActiveRecord::Base protected def refresh_notification_count - begin - if user.has_attribute?(:seen_notification_id) - user.notifications.reset - user.publish_notifications_state - else - User.find_by(id: user.id).publish_notifications_state - end - rescue ActiveRecord::RecordNotFound - # happens when we delete a user + if user_id + User.find_by(id: user_id)&.publish_notifications_state end end