From ecb1f57efe3f6f1a3724527bd3c476c40ff8da16 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Mon, 15 Aug 2022 19:58:42 +0530 Subject: [PATCH] chore: Improve memory usage in RemoveStaleNotificationsJob (#5271) The job we introduced recently for removing the stale migrations would time out in instances with a large amount of deleted data. So improving it for better memory utilization. --- app/jobs/migration/remove_stale_notifications_job.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/jobs/migration/remove_stale_notifications_job.rb b/app/jobs/migration/remove_stale_notifications_job.rb index fcd8bee8d..ef6dff68d 100644 --- a/app/jobs/migration/remove_stale_notifications_job.rb +++ b/app/jobs/migration/remove_stale_notifications_job.rb @@ -12,9 +12,8 @@ class Migration::RemoveStaleNotificationsJob < ApplicationJob deleted_ids = [] Message.unscoped.distinct.pluck(:inbox_id).each_slice(1000) do |id_list| - deleted_ids << (id_list - Inbox.where(id: id_list).pluck(:id)) + deleted_ids = (id_list - Inbox.where(id: id_list).pluck(:id)) + Message.where(inbox_id: deleted_ids.flatten).destroy_all end - - Message.where(inbox_id: deleted_ids.flatten).destroy_all end end