DEV: do not use find_each for `avatars:clean` task

https://review.discourse.org/t/fix-show-available-details-when-rescuing-error/2865
This commit is contained in:
Arpit Jalan 2019-04-25 18:39:10 +05:30
parent 761e1e25f7
commit 0d331d33c3
1 changed files with 7 additions and 3 deletions

View File

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