After our migration (back) to Amazon S3, we appear to have quite a few images where the optimized versions are missing, but the full-size ones are there (example).
There is a Rake task for regenerating optimized images, but it only appears to work with local storage. How would I do this with remote images?
I’m afraid you’ll have to write your own rake task for that. Here’s some pseudo code on how I’d start
FOR EACH oi IN optimized_images
IF file_exists_on_s3?(oi.upload.url) AND NOT file_exists_on_s3?(oi.url) THEN
OptimizedImage.create_for(oi.upload, oi.width, oi.height)
END IF
END FOR
I just migrated to S3, and indeed the /optimized/ folder is not transferred in the migration. I’d like to get rid of the /optimized/ folder, as it adds significant weight to my daily backup.
module FileStore
class S3Store < BaseStore
...
def path_for(upload)
url = upload&.url
if url && url[/^\/[^"]/]
FileStore::LocalStore.new.path_for(upload)
else
url
end
end
...
end
end
解決策:最新のコード - 新しいアップロードのプロフィール写真が表示されるようになった
module FileStore
class S3Store < BaseStore
...
def path_for(upload)
url = upload&.url
FileStore::LocalStore.new.path_for(upload) if url && url[/^\/[^"]/]
end
...
end
end
RailsMultisite::ConnectionManagement.each_connection do |db|
Upload.where(extension: "unknown").each do |upload|
upload.update(extension: File.extname(upload.url).gsub(".",""))
end
OptimizedImage.destroy_all
UserAvatar.all.each {|ua| uaid = ua.gravatar_upload_id || ua.custom_upload_id;
Jobs::CreateAvatarThumbnails.perform_async(upload_id: uaid) if uaid }
end