mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 20:05:55 +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
|
end
|
||||||
|
|
||||||
def self.destroy_notifications(user)
|
def self.destroy_notifications(user)
|
||||||
# Find all notifications where user is the only reference
|
user.notifications.in_batches(of: 1000).destroy_all
|
||||||
# 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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue