From 24fe08230fc858933af516446bf5ccd29f417388 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Tue, 18 Aug 2020 15:37:11 +1000 Subject: [PATCH] FEATURE: ensure posts are rebaked when missing is fixed This ensures any corrupt optimized images are removed and re-created --- lib/tasks/uploads.rake | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake index 55e17d07b70..2fa4a110e20 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