mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-22 13:04:30 +08:00
Fix notification destroy in user data deletion [SCI-11549]
This commit is contained in:
parent
5fc63178a3
commit
5d16a1c445
1 changed files with 1 additions and 15 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue