FEATURE: ensure posts are rebaked when missing is fixed

FEATURE: ensure posts are rebaked when missing is fixed

This ensures any corrupt optimized images are removed and re-created

diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake
index 55e17d0..2fa4a11 100644
--- a/lib/tasks/uploads.rake
+++ b/lib/tasks/uploads.rake
@@ -1092,6 +1092,16 @@ def fix_missing_s3
       # we do not fix sha, it may be wrong for arbitrary reasons, if we correct it
       # we may end up breaking posts
       upload.update!(etag: fixed_upload.etag, url: fixed_upload.url, verified: nil)
+
+      OptimizedImage.where(upload_id: upload.id).destroy_all
+      rebake_ids = PostUpload.where(upload_id: upload.id).pluck(:post_id)
+
+      if rebake_ids.present?
+        Post.where(id: rebake_ids).each do |post|
+          puts "rebake post #{post.id}"
+          post.rebake!
+        end
+      end
     end
   end
 

GitHub sha: 24fe0823

1 Like