From 79ee6a515de79d11b1140e3b26a5bb6225e31384 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 4 Jan 2021 18:24:05 -0600 Subject: [PATCH] post regenerations: refresh Cloudflare when post is regenerated. Purge cached thumbnails from Cloudflare when a post is regenerated. This is necessary because regenerating a post may change the thumbnail, and if we don't purge the cache from Cloudflare then users will still see the old thumbnail. We have do this before updating IQDB because if we don't, IQDB will see the old cached thumbnail and index the wrong image. This may be racy because the thumbnail might not be completely purged from Cloudflare before it's downloaded by IQDB. --- app/models/post.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/post.rb b/app/models/post.rb index d3a3df27e..60b2b8730 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1338,11 +1338,19 @@ class Post < ApplicationRecord else media_file = MediaFile.open(file, frame_data: pixiv_ugoira_frame_data) UploadService::Utils.process_resizes(self, nil, id, media_file: media_file) + + # XXX This may be racy; the thumbnail may not be purged from Cloudflare by the time IQDB tries to download it. + purge_cached_urls! update_iqdb_async ModAction.log("<@#{user.name}> regenerated image samples for post ##{id}", :post_regenerate, user) end end + + def purge_cached_urls! + urls = [preview_file_url, large_file_url] + CloudflareService.new.purge_cache(urls) + end end module IqdbMethods