From c1a93ad3c3aaa45d7481c42442bedf6297f8aa86 Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Fri, 23 Apr 2021 09:35:40 -0500 Subject: [PATCH] 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 --- app/services/edge_cache/bust_article.rb | 36 +++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/app/services/edge_cache/bust_article.rb b/app/services/edge_cache/bust_article.rb index 9f6d32bba..0de88a3c5 100644 --- a/app/services/edge_cache/bust_article.rb +++ b/app/services/edge_cache/bust_article.rb @@ -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