2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-05-28 09:50:49 +08:00
|
|
|
desc "Refresh all avatars (download missing gravatars, refresh system)"
|
|
|
|
task "avatars:refresh" => :environment do
|
|
|
|
i = 0
|
2014-06-27 01:50:16 +08:00
|
|
|
|
2014-05-28 09:50:49 +08:00
|
|
|
puts "Refreshing avatars"
|
|
|
|
puts
|
2014-06-27 01:50:16 +08:00
|
|
|
|
2014-05-28 09:50:49 +08:00
|
|
|
User.find_each do |user|
|
2019-04-14 16:56:12 +08:00
|
|
|
begin
|
|
|
|
user.refresh_avatar
|
|
|
|
user.user_avatar.update_gravatar!
|
2019-04-15 16:36:29 +08:00
|
|
|
rescue => e
|
|
|
|
puts "", "Failed to refresh avatar for #{user.username}", e, e.backtrace.join("\n")
|
2019-04-14 16:56:12 +08:00
|
|
|
end
|
2014-06-23 22:57:21 +08:00
|
|
|
putc "." if (i += 1) % 10 == 0
|
|
|
|
end
|
2014-06-27 01:50:16 +08:00
|
|
|
|
2014-06-23 22:57:21 +08: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-27 01:50:16 +08:00
|
|
|
|
2014-06-23 22:57:21 +08:00
|
|
|
puts "Cleaning up avatar thumbnails"
|
|
|
|
puts
|
2014-06-26 05:06:15 +08:00
|
|
|
|
2019-04-25 21:09:10 +08:00
|
|
|
optimized_image_ids =
|
|
|
|
OptimizedImage.where(
|
|
|
|
"upload_id IN (SELECT custom_upload_id FROM user_avatars) OR
|
2016-05-20 15:12:25 +08:00
|
|
|
upload_id IN (SELECT gravatar_upload_id FROM user_avatars) OR
|
2019-04-25 22:49:52 +08:00
|
|
|
upload_id IN (SELECT uploaded_avatar_id FROM users)",
|
|
|
|
).pluck(:id)
|
2019-04-25 21:09:10 +08:00
|
|
|
|
|
|
|
optimized_image_ids.each do |id|
|
2018-02-23 20:45:07 +08:00
|
|
|
begin
|
2019-04-25 21:09:10 +08:00
|
|
|
optimized_image = OptimizedImage.find_by(id: id)
|
2024-05-27 18:27:13 +08:00
|
|
|
next if optimized_image.blank?
|
2018-02-23 20:45:07 +08:00
|
|
|
optimized_image.destroy!
|
2019-04-15 16:36:29 +08:00
|
|
|
rescue => e
|
2019-04-25 21:09:10 +08:00
|
|
|
puts "", "Failed to cleanup avatar (optimized_image id: #{id})", e, e.backtrace.join("\n")
|
2018-02-23 20:45:07 +08:00
|
|
|
end
|
2014-06-23 22:57:21 +08:00
|
|
|
putc "." if (i += 1) % 10 == 0
|
2014-05-28 09:50:49 +08:00
|
|
|
end
|
2014-06-27 01:50:16 +08:00
|
|
|
|
2014-05-28 09:50:49 +08:00
|
|
|
puts
|
|
|
|
end
|