Cleanup articles cache busting (#13467)

* Extract repeated calls to cache_bust.call to iteration over list

This mirrors what the EdgeCache::BustUser service looks like.

It might make sense to have cached_article_paths be a method accepting
a block and yielding paths, and including the collections cache paths
as well.

* Move article path information into a separate method

BustArticle.call now only knows to bust cache for each path associated
with the article, the information about which paths to clear is moved
to a separate `paths_for` method.

I may have gone overboard on this.

* Remove extra blank line
This commit is contained in:
Daniel Uber 2021-04-23 09:35:40 -05:00 committed by GitHub
parent ee66e4cf7d
commit c1a93ad3c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,23 +14,37 @@ module EdgeCache
cache_bust = EdgeCache::Bust.new
cache_bust.call(article.path)
cache_bust.call("/#{article.user.username}")
cache_bust.call("#{article.path}/")
cache_bust.call("#{article.path}?i=i")
cache_bust.call("#{article.path}/?i=i")
cache_bust.call("#{article.path}/comments")
cache_bust.call("#{article.path}?preview=#{article.password}")
cache_bust.call("#{article.path}?preview=#{article.password}&i=i")
cache_bust.call("/#{article.organization.slug}") if article.organization.present?
paths_for(article) do |path|
cache_bust.call(path)
end
bust_home_pages(cache_bust, article)
bust_tag_pages(cache_bust, article)
cache_bust.call("/api/articles/#{article.id}")
end
def self.paths_for(article)
paths = [
article.path,
"/#{article.user.username}",
"#{article.path}/",
"#{article.path}?i=i",
"#{article.path}/?i=i",
"#{article.path}/comments",
"#{article.path}?preview=#{article.password}",
"#{article.path}?preview=#{article.password}&i=i",
"/api/articles/#{article.id}",
]
paths.each do |path|
yield path
end
yield "/#{article.organization.slug}" if article.organization.present?
return unless article.collection_id
article.collection.articles.find_each do |collection_article|
cache_bust.call(collection_article.path)
yield collection_article.path
end
end