From c81a37c1d3f864cf0a00386dab29da78f222e3a5 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Fri, 4 May 2018 19:52:43 +0200 Subject: Use find_in_batches instead of destroy_all destroy_all loads all records at once --- app/models/concerns/with_uploads.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/concerns/with_uploads.rb b/app/models/concerns/with_uploads.rb index 101d09f161d..3d99889c131 100644 --- a/app/models/concerns/with_uploads.rb +++ b/app/models/concerns/with_uploads.rb @@ -32,6 +32,8 @@ module WithUploads # it can not be done in after_commit because FileUploader requires loads # associated model on destroy (which is already deleted in after_commit) def destroy_file_uploads - self.uploads.where(uploader: FILE_UPLOADERS).destroy_all + self.uploads.where(uploader: FILE_UPLOADERS).find_each do |upload| + upload.destroy + end end end -- cgit v1.2.1