Some fixes related to optimized images (#4233)

* FIX: No need to manually include relation.

* FIX: OR instead of chaining relation.
This commit is contained in:
Guo Xiang Tan 2016-05-20 15:12:25 +08:00 committed by Régis Hanol
parent 0cf5a1705a
commit 0634834009
2 changed files with 3 additions and 4 deletions

View file

@ -41,7 +41,6 @@ class Upload < ActiveRecord::Base
)
if thumbnail
optimized_images << thumbnail
self.width = width
self.height = height
save(validate: false)

View file

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