From 5d16a1c4456a083d214aca9c2fe3b9c97d851b90 Mon Sep 17 00:00:00 2001 From: Andrej Date: Thu, 13 Feb 2025 14:50:22 +0100 Subject: [PATCH] Fix notification destroy in user data deletion [SCI-11549] --- app/services/user_data_deletion.rb | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/app/services/user_data_deletion.rb b/app/services/user_data_deletion.rb index fef2dc995..f4270a45a 100644 --- a/app/services/user_data_deletion.rb +++ b/app/services/user_data_deletion.rb @@ -112,20 +112,6 @@ class UserDataDeletion end def self.destroy_notifications(user) - # Find all notifications where user is the only reference - # on the notification, and destroy all such notifications - # (user_notifications are destroyed when notification is - # destroyed). We try to do this efficiently (hence in_groups_of). - nids_all = user.notifications.pluck(:id) - nids_all.in_groups_of(1000, false) do |nids| - Notification - .where(id: nids) - .joins(:user_notifications) - .group('notifications.id') - .having('count(notification_id) <= 1') - .destroy_all - end - # Now, simply destroy all user notification relations left - user.user_notifications.destroy_all + user.notifications.in_batches(of: 1000).destroy_all end end