BUGFIX: actually clean up all avatar thumbnails

This commit is contained in:
Régis Hanol 2014-06-25 23:06:15 +02:00
parent 18a2e7901e
commit 610f2dabd1
1 changed files with 5 additions and 2 deletions

View File

@ -16,8 +16,11 @@ task "avatars:clean" => :environment do
i = 0
puts "Cleaning up avatar thumbnails"
puts
custom_upload_ids = UserAvatar.where.not(custom_upload_id: nil).pluck(:custom_upload_id)
OptimizedImage.where("upload_id IN (?)", custom_upload_ids).find_each do |optimized_image|
OptimizedImage.where("upload_id IN (SELECT custom_upload_id FROM user_avatars")
.where("upload_id IN (SELECT gravatar_upload_id FROM user_avatars")
.where("upload_id IN (SELECT uploaded_avatar_id FROM users")
.find_each do |optimized_image|
optimized_image.destroy!
putc "." if (i += 1) % 10 == 0
end