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.
This commit is contained in:
evazion
2021-01-04 18:24:05 -06:00
parent b6f9c9a866
commit 79ee6a515d

View File

@@ -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