diff --git a/app/models/card/readable.rb b/app/models/card/readable.rb index 903db2d71..9c272dd75 100644 --- a/app/models/card/readable.rb +++ b/app/models/card/readable.rb @@ -14,8 +14,9 @@ module Card::Readable end def remove_inaccessible_notifications - User.find_each do |user| - all_notifications_for(user).destroy_all unless accessible_to?(user) + accessible_user_ids = board.accesses.pluck(:user_id) + notification_sources.each do |sources| + inaccessible_notifications_from(sources, accessible_user_ids).in_batches.destroy_all end end @@ -44,6 +45,14 @@ module Card::Readable Event.where(eventable: comments) end + def inaccessible_notifications_from(sources, accessible_user_ids) + Notification.where(source: sources).where.not(user_id: accessible_user_ids) + end + + def notification_sources + [ events, comment_creation_events, mentions, comment_mentions ] + end + def mention_notification_sources mentions.or(comment_mentions) end