From 063483400942819287979e4204515cc2d39ae9cf Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 20 May 2016 15:12:25 +0800 Subject: [PATCH] Some fixes related to optimized images (#4233) * FIX: No need to manually include relation. * FIX: OR instead of chaining relation. --- app/models/upload.rb | 1 - lib/tasks/avatars.rake | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/models/upload.rb b/app/models/upload.rb index 5783a94d2d8..dec7de8f2f7 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -41,7 +41,6 @@ class Upload < ActiveRecord::Base ) if thumbnail - optimized_images << thumbnail self.width = width self.height = height save(validate: false) diff --git a/lib/tasks/avatars.rake b/lib/tasks/avatars.rake index c27dac792ff..4c1da8fd54f 100644 --- a/lib/tasks/avatars.rake +++ b/lib/tasks/avatars.rake @@ -21,9 +21,9 @@ task "avatars:clean" => :environment do puts "Cleaning up avatar thumbnails" puts - 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)") + 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| optimized_image.destroy! putc "." if (i += 1) % 10 == 0