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:
parent
ee66e4cf7d
commit
c1a93ad3c3
1 changed files with 25 additions and 11 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue