Use find_in_batches instead of destroy_all

destroy_all loads all records at once
This commit is contained in:
Jan Provaznik 2018-05-04 19:52:43 +02:00
parent 7da3b2cdd0
commit c81a37c1d3
1 changed files with 3 additions and 1 deletions

View File

@ -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