Tighten scope on card notification removals

* Iterate each association separately to favor db indexing
* Pluck user IDs rather than select to avoid correlated subquery
This commit is contained in:
Jeremy Daer
2025-12-03 15:32:29 -08:00
parent 49139b7a14
commit f440b0243e
+11 -2
View File
@@ -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