cloudflare: fix purging of cached urls.
* Switch CloudflareService from HttpartyCache to Danbooru::Http. * Purge cached urls from Cloudflare when a post is replaced and the md5 doesn't change. This happens when a corrupted image is replaced or thumbnails are regenerated. Before we purged urls when a post was expunged, which was unneeded because those urls can expire naturally. It was also wrong because the subdomains were hardcoded, the urls used http:// instead of https://, and we didn't account for tagged urls.
This commit is contained in:
@@ -3,7 +3,7 @@ module Danbooru
|
||||
attr_accessor :cache, :http
|
||||
|
||||
class << self
|
||||
delegate :get, :post, :cache, :auth, :basic_auth, :headers, to: :new
|
||||
delegate :get, :post, :delete, :cache, :auth, :basic_auth, :headers, to: :new
|
||||
end
|
||||
|
||||
def get(url, **options)
|
||||
@@ -14,6 +14,10 @@ module Danbooru
|
||||
request(:post, url, **options)
|
||||
end
|
||||
|
||||
def delete(url, **options)
|
||||
request(:delete, url, **options)
|
||||
end
|
||||
|
||||
def cache(expiry)
|
||||
dup.tap { |o| o.cache = expiry.to_i }
|
||||
end
|
||||
@@ -41,7 +45,7 @@ module Danbooru
|
||||
end
|
||||
|
||||
def cached_request(method, url, **options)
|
||||
key = Cache.hash({ method: method, url: url, **options }.to_json)
|
||||
key = Cache.hash({ method: method, url: url, headers: http.default_options.headers.to_h, **options }.to_json)
|
||||
|
||||
cached_response = Cache.get(key, @cache) do
|
||||
response = raw_request(method, url, **options)
|
||||
|
||||
Reference in New Issue
Block a user