2022-08-10 11:46:46 +00:00
|
|
|
# Delete migration and spec after 2 consecutive releases.
|
|
|
|
class Migration::RemoveStaleNotificationsJob < ApplicationJob
|
|
|
|
queue_as :scheduled_jobs
|
|
|
|
|
|
|
|
def perform
|
|
|
|
remove_invalid_messages
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def remove_invalid_messages
|
|
|
|
deleted_ids = []
|
2022-08-10 13:08:37 +00:00
|
|
|
|
|
|
|
Message.unscoped.distinct.pluck(:inbox_id).each_slice(1000) do |id_list|
|
2022-08-15 14:28:42 +00:00
|
|
|
deleted_ids = (id_list - Inbox.where(id: id_list).pluck(:id))
|
|
|
|
Message.where(inbox_id: deleted_ids.flatten).destroy_all
|
2022-08-10 11:46:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|