2014-05-27 20:50:49 -05:00
|
|
|
desc "Refresh all avatars (download missing gravatars, refresh system)"
|
|
|
|
task "avatars:refresh" => :environment do
|
|
|
|
i = 0
|
2014-06-26 12:50:16 -05:00
|
|
|
|
2014-05-27 20:50:49 -05:00
|
|
|
puts "Refreshing avatars"
|
|
|
|
puts
|
2014-06-26 12:50:16 -05:00
|
|
|
|
2014-05-27 20:50:49 -05:00
|
|
|
User.find_each do |user|
|
|
|
|
user.refresh_avatar
|
2014-06-06 12:19:32 -05:00
|
|
|
user.user_avatar.update_gravatar!
|
2014-06-23 09:57:21 -05:00
|
|
|
putc "." if (i += 1) % 10 == 0
|
|
|
|
end
|
2014-06-26 12:50:16 -05:00
|
|
|
|
2014-06-23 09:57:21 -05:00
|
|
|
puts
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Clean up all avatar thumbnails (use this when the thumbnail algorithm changes)"
|
|
|
|
task "avatars:clean" => :environment do
|
|
|
|
i = 0
|
2014-06-26 12:50:16 -05:00
|
|
|
|
2014-06-23 09:57:21 -05:00
|
|
|
puts "Cleaning up avatar thumbnails"
|
|
|
|
puts
|
2014-06-25 16:06:15 -05:00
|
|
|
|
2016-05-20 02:12:25 -05:00
|
|
|
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)")
|
2017-07-27 20:20:09 -05:00
|
|
|
.find_each do |optimized_image|
|
2018-02-23 06:45:07 -06:00
|
|
|
begin
|
|
|
|
optimized_image.destroy!
|
|
|
|
rescue
|
|
|
|
# skip
|
|
|
|
end
|
2014-06-23 09:57:21 -05:00
|
|
|
putc "." if (i += 1) % 10 == 0
|
2014-05-27 20:50:49 -05:00
|
|
|
end
|
2014-06-26 12:50:16 -05:00
|
|
|
|
2014-05-27 20:50:49 -05:00
|
|
|
puts
|
|
|
|
end
|