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:
parent
761e1e25f7
commit
0d331d33c3
|
@ -25,14 +25,18 @@ task "avatars:clean" => :environment do
|
||||||
puts "Cleaning up avatar thumbnails"
|
puts "Cleaning up avatar thumbnails"
|
||||||
puts
|
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 gravatar_upload_id FROM user_avatars) OR
|
||||||
upload_id IN (SELECT uploaded_avatar_id FROM users)")
|
upload_id IN (SELECT uploaded_avatar_id FROM users)")
|
||||||
.find_each do |optimized_image|
|
.pluck(:id)
|
||||||
|
|
||||||
|
optimized_image_ids.each do |id|
|
||||||
begin
|
begin
|
||||||
|
optimized_image = OptimizedImage.find_by(id: id)
|
||||||
|
next unless optimized_image.present?
|
||||||
optimized_image.destroy!
|
optimized_image.destroy!
|
||||||
rescue => e
|
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
|
end
|
||||||
putc "." if (i += 1) % 10 == 0
|
putc "." if (i += 1) % 10 == 0
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue