From 0d331d33c3b205b9a44477f246bd4f241d196f4f Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Thu, 25 Apr 2019 18:39:10 +0530 Subject: [PATCH] DEV: do not use find_each for `avatars:clean` task https://review.discourse.org/t/fix-show-available-details-when-rescuing-error/2865 --- lib/tasks/avatars.rake | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/tasks/avatars.rake b/lib/tasks/avatars.rake index b53b6e47528..b803f863691 100644 --- a/lib/tasks/avatars.rake +++ b/lib/tasks/avatars.rake @@ -25,14 +25,18 @@ task "avatars:clean" => :environment do puts "Cleaning up avatar thumbnails" puts - OptimizedImage.where("upload_id IN (SELECT custom_upload_id FROM user_avatars) OR + optimized_image_ids = OptimizedImage.where("upload_id IN (SELECT custom_upload_id FROM user_avatars) OR upload_id IN (SELECT gravatar_upload_id FROM user_avatars) OR upload_id IN (SELECT uploaded_avatar_id FROM users)") - .find_each do |optimized_image| + .pluck(:id) + + optimized_image_ids.each do |id| begin + optimized_image = OptimizedImage.find_by(id: id) + next unless optimized_image.present? optimized_image.destroy! rescue => e - puts "", "Failed to cleanup avatar (optimized_image_id: #{optimized_image.id}, optimized_image_url: #{optimized_image.url})", e, e.backtrace.join("\n") + puts "", "Failed to cleanup avatar (optimized_image id: #{id})", e, e.backtrace.join("\n") end putc "." if (i += 1) % 10 == 0 end