chore: migration to remove stale data

This commit is contained in:
Sojan 2022-08-09 16:57:35 +02:00
parent 267b19db3d
commit b9175b5877

View file

@ -12,7 +12,7 @@ class Migration::RemoveStaleNotificationsJob < ApplicationJob
def remove_conversation_notifications def remove_conversation_notifications
deleted_ids = [] deleted_ids = []
Notification.where(primary_actor_type: 'Conversation').pluck(:primary_actor_id).uniq.each_slice(1000) do |id_list| Notification.where(primary_actor_type: 'Conversation').pluck(:primary_actor_id).uniq.each_slice(1000) do |id_list|
deleted_ids << id_list - Conversation.where(id: id_list).pluck(:id) deleted_ids << (id_list - Conversation.where(id: id_list).pluck(:id))
end end
Notification.where(primary_actor_type: 'Conversation', primary_actor_id: deleted_ids).destroy_all Notification.where(primary_actor_type: 'Conversation', primary_actor_id: deleted_ids).destroy_all
end end
@ -20,7 +20,7 @@ class Migration::RemoveStaleNotificationsJob < ApplicationJob
def remove_message_notifications def remove_message_notifications
deleted_ids = [] deleted_ids = []
Notification.where(primary_actor_type: 'Message').pluck(:primary_actor_id).uniq.each_slice(1000) do |id_list| Notification.where(primary_actor_type: 'Message').pluck(:primary_actor_id).uniq.each_slice(1000) do |id_list|
deleted_ids << id_list - Message.where(id: id_list).pluck(:id) deleted_ids << (id_list - Message.where(id: id_list).pluck(:id))
end end
Notification.where(primary_actor_type: 'Message', primary_actor_id: deleted_ids).destroy_all Notification.where(primary_actor_type: 'Message', primary_actor_id: deleted_ids).destroy_all
end end