From f7322c05adb214aca16cbf17bc86bbf640c845a1 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 2 Jul 2018 12:41:53 +0800 Subject: [PATCH] FIX: Avoid `destroy_all` in `Jobs::CleanUpUploads`. `destroy_all` loads all the relation into memory as once. See https://github.com/rails/rails/issues/22510 --- app/jobs/scheduled/clean_up_uploads.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/scheduled/clean_up_uploads.rb b/app/jobs/scheduled/clean_up_uploads.rb index d84fddce302..a4bb083ce33 100644 --- a/app/jobs/scheduled/clean_up_uploads.rb +++ b/app/jobs/scheduled/clean_up_uploads.rb @@ -10,7 +10,7 @@ module Jobs .where("retain_hours IS NULL OR created_at < current_timestamp - interval '1 hour' * retain_hours") .where("created_at < ?", grace_period.hour.ago) .where(url: "") - .destroy_all + .find_each(&:destroy!) return unless SiteSetting.clean_up_uploads?