Users are discussing issues with missing optimized images after migrating to Amazon S3 storage in Discourse. uppfinnarn notes that optimized images are missing post-migration, and the standard rake task doesn’t work with remote storage. zogstrip suggests writing a custom rake task to regenerate missing optimized images by checking S3 for existing full-size files. supermathie shares a solution involving deleting all optimized images and regenerating them via Jobs::CreateAvatarThumbnails, followed by rake posts:rebake for post images. ashishprajapati provides a workaround for profile picture issues, including fixing extension values for uploads and using a rake task to regenerate avatar thumbnails. markersocial attempts to regenerate avatar thumbnails but finds that jobs are not generating new files, suspecting read-only mode may be blocking processing. The discussion highlights the need for custom scripts and careful handling of S3 migration issues.
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