Merge pull request #4420 from tgxworld/prioritize_user_avataras

Prioritize user avatars when regenerating missing optimized images.
This commit is contained in:
Guo Xiang Tan 2016-08-26 07:58:58 +08:00 committed by GitHub
commit b1c8ede617

View File

@ -390,11 +390,20 @@ def regenerate_missing_optimized
public_directory = "#{Rails.root}/public"
missing_uploads = Set.new
OptimizedImage.includes(:upload)
avatar_upload_ids = UserAvatar.all.pluck(:custom_upload_id, :gravatar_upload_id).flatten.compact
default_scope = OptimizedImage.includes(:upload)
[
default_scope
.where("optimized_images.upload_id IN (?)", avatar_upload_ids),
default_scope
.where("optimized_images.upload_id NOT IN (?)", avatar_upload_ids)
.where("LENGTH(COALESCE(url, '')) > 0")
.where("width > 0 AND height > 0")
.find_each do |optimized_image|
].each do |scope|
scope.find_each do |optimized_image|
upload = optimized_image.upload
next unless optimized_image.url =~ /^\/[^\/]/
@ -430,6 +439,7 @@ def regenerate_missing_optimized
putc "."
end
end
end
puts "", "Done"