diff --git a/app/services/edge_cache/bust/fastly.rb b/app/services/edge_cache/bust/fastly.rb index 8299085c4a619..5a99d3e1bfa73 100644 --- a/app/services/edge_cache/bust/fastly.rb +++ b/app/services/edge_cache/bust/fastly.rb @@ -17,10 +17,11 @@ def self.fastly_purge(path) private_class_method :fastly_purge def self.urls(path) - [ - URL.url(path), - URL.url("#{path}?i=i"), - ] + [URL.url(path)] << if path.include?("?") + URL.url("#{path}&i=i") + else + URL.url("#{path}?i=i") + end end private_class_method :urls end diff --git a/app/services/edge_cache/bust_article.rb b/app/services/edge_cache/bust_article.rb index fcd2e6b119ecb..e39d18c6dcce2 100644 --- a/app/services/edge_cache/bust_article.rb +++ b/app/services/edge_cache/bust_article.rb @@ -24,13 +24,10 @@ def self.call(article) def self.paths_for(article, &block) paths = [ article.path, - "/#{article.user.username}", "#{article.path}/", - "#{article.path}?i=i", - "#{article.path}/?i=i", + "/#{article.user.username}", "#{article.path}/comments", "#{article.path}?preview=#{article.password}", - "#{article.path}?preview=#{article.password}&i=i", "/api/articles/#{article.id}", ] @@ -47,13 +44,12 @@ def self.paths_for(article, &block) def self.bust_home_pages(cache_bust, article) if article.published_at.to_i > Time.current.to_i + # TODO cache_bust.call("/") - cache_bust.call("?i=i") end if article.video.present? && article.published_at.to_i > 10.days.ago.to_i cache_bust.call("/videos") - cache_bust.call("/videos?i=i") end TIMEFRAMES.each do |timestamp, interval| @@ -61,13 +57,10 @@ def self.bust_home_pages(cache_bust, article) .order(public_reactions_count: :desc).limit(3).ids.include?(article.id) cache_bust.call("/top/#{interval}") - cache_bust.call("/top/#{interval}?i=i") - cache_bust.call("/top/#{interval}/?i=i") end if article.published && article.published_at > 1.hour.ago cache_bust.call("/latest") - cache_bust.call("/latest?i=i") end cache_bust.call("/") if Article.published.order(hotness_score: :desc).limit(4).ids.include?(article.id) @@ -81,7 +74,6 @@ def self.bust_tag_pages(cache_bust, article) article.tag_list.each do |tag| if article.published_at.to_i > 2.minutes.ago.to_i cache_bust.call("/t/#{tag}/latest") - cache_bust.call("/t/#{tag}/latest?i=i") end TIMEFRAMES.each do |timestamp, interval| @@ -89,8 +81,6 @@ def self.bust_tag_pages(cache_bust, article) .order(public_reactions_count: :desc).limit(3).ids.include?(article.id) cache_bust.call("/top/#{interval}") - cache_bust.call("/top/#{interval}?i=i") - cache_bust.call("/top/#{interval}/?i=i") 12.times do |i| cache_bust.call("/api/articles?tag=#{tag}&top=#{i}") end @@ -101,7 +91,6 @@ def self.bust_tag_pages(cache_bust, article) .order(hotness_score: :desc).limit(2).ids.include?(article.id) cache_bust.call("/t/#{tag}") - cache_bust.call("/t/#{tag}?i=i") end end diff --git a/app/services/edge_cache/bust_comment.rb b/app/services/edge_cache/bust_comment.rb index bbb9d1fa231e7..254d41767add3 100644 --- a/app/services/edge_cache/bust_comment.rb +++ b/app/services/edge_cache/bust_comment.rb @@ -12,7 +12,6 @@ def self.call(commentable) commentable.comments.includes(:user).find_each do |comment| cache_bust.call(comment.path) - cache_bust.call("#{comment.path}?i=i") end cache_bust.call("#{commentable.path}/comments/*") @@ -25,8 +24,6 @@ def self.bust_article_comment(cache_bust, article) return unless article.decorate.discussion? cache_bust.call("/") - cache_bust.call("/?i=i") - cache_bust.call("?i=i") end private_class_method :bust_article_comment diff --git a/app/services/edge_cache/bust_listings.rb b/app/services/edge_cache/bust_listings.rb index 23177652f8ba3..712c603400af2 100644 --- a/app/services/edge_cache/bust_listings.rb +++ b/app/services/edge_cache/bust_listings.rb @@ -8,9 +8,7 @@ def self.call(listing) cache_bust = EdgeCache::Bust.new cache_bust.call("/listings") - cache_bust.call("/listings?i=i") cache_bust.call("/listings/#{listing.category}/#{listing.slug}") - cache_bust.call("/listings/#{listing.category}/#{listing.slug}?i=i") cache_bust.call("/listings/#{listing.category}") end end diff --git a/app/services/edge_cache/bust_page.rb b/app/services/edge_cache/bust_page.rb index 17cf84528f950..2ae3ca8a593c7 100644 --- a/app/services/edge_cache/bust_page.rb +++ b/app/services/edge_cache/bust_page.rb @@ -5,9 +5,7 @@ def self.call(slug) cache_bust = EdgeCache::Bust.new cache_bust.call("/page/#{slug}") - cache_bust.call("/page/#{slug}?i=i") cache_bust.call("/#{slug}") - cache_bust.call("/#{slug}?i=i") end end end diff --git a/app/services/edge_cache/bust_tag.rb b/app/services/edge_cache/bust_tag.rb index 4ef8bd04217bb..db69de7e158c4 100644 --- a/app/services/edge_cache/bust_tag.rb +++ b/app/services/edge_cache/bust_tag.rb @@ -7,8 +7,6 @@ def self.call(tag) cache_bust = EdgeCache::Bust.new cache_bust.call("/t/#{tag.name}") - cache_bust.call("/t/#{tag.name}?i=i") - cache_bust.call("/t/#{tag.name}/?i=i") cache_bust.call("/t/#{tag.name}/") cache_bust.call("/tags") end diff --git a/app/services/edge_cache/bust_user.rb b/app/services/edge_cache/bust_user.rb index 259074aa37620..456b3dec2615e 100644 --- a/app/services/edge_cache/bust_user.rb +++ b/app/services/edge_cache/bust_user.rb @@ -7,12 +7,8 @@ def self.call(user) user_id = user.id paths = [ "/#{username}", - "/#{username}?i=i", "/#{username}/comments", - "/#{username}/comments?i=i", - "/#{username}/comments/?i=i", "/live/#{username}", - "/live/#{username}?i=i", "/feed/#{username}", "/api/users/#{user_id}", ] diff --git a/spec/services/edge_cache/bust_article_spec.rb b/spec/services/edge_cache/bust_article_spec.rb index 32061ecab4aee..7b182d895d0c7 100644 --- a/spec/services/edge_cache/bust_article_spec.rb +++ b/spec/services/edge_cache/bust_article_spec.rb @@ -28,7 +28,7 @@ it "busts the cache" do described_class.call(article) expect(article).to have_received(:purge).once - expect(cache_bust).to have_received(:call).exactly(9).times + expect(cache_bust).to have_received(:call).exactly(6).times expect(cache_bust).to have_received(:call).with(article.path).once expect(described_class).to have_received(:bust_home_pages).with(cache_bust, article).once expect(described_class).to have_received(:bust_tag_pages).with(cache_bust, article).once diff --git a/spec/services/edge_cache/bust_listings_spec.rb b/spec/services/edge_cache/bust_listings_spec.rb index b9ee03234c72b..a6b7fdccc7c5e 100644 --- a/spec/services/edge_cache/bust_listings_spec.rb +++ b/spec/services/edge_cache/bust_listings_spec.rb @@ -7,10 +7,8 @@ let(:paths) do [ "/listings", - "/listings?i=i", - "/listings/#{listing.category}/#{listing.slug}", - "/listings/#{listing.category}/#{listing.slug}?i=i", "/listings/#{listing.category}", + "/listings/#{listing.category}/#{listing.slug}", ] end @@ -23,7 +21,7 @@ end end - it "busts the cache" do + it "busts the cache", :aggregate_failures do described_class.call(listing) expect(listing).to have_received(:purge_all) diff --git a/spec/services/edge_cache/bust_page_spec.rb b/spec/services/edge_cache/bust_page_spec.rb index 13f64bb49078c..7f725b72b02a1 100644 --- a/spec/services/edge_cache/bust_page_spec.rb +++ b/spec/services/edge_cache/bust_page_spec.rb @@ -6,9 +6,7 @@ let(:paths) do [ "/page/#{slug}", - "/page/#{slug}?i=i", "/#{slug}", - "/#{slug}?i=i", ] end @@ -20,7 +18,7 @@ end end - it "busts the cache" do + it "busts the cache", :aggregate_failures do described_class.call(slug) paths.each do |path| diff --git a/spec/services/edge_cache/bust_tag_spec.rb b/spec/services/edge_cache/bust_tag_spec.rb index 92f67cd23ca3a..32eddace32b9e 100644 --- a/spec/services/edge_cache/bust_tag_spec.rb +++ b/spec/services/edge_cache/bust_tag_spec.rb @@ -6,8 +6,6 @@ let(:paths) do [ "/t/#{tag.name}", - "/t/#{tag.name}?i=i", - "/t/#{tag.name}/?i=i", "/t/#{tag.name}/", "/tags", ] @@ -23,7 +21,7 @@ allow(tag).to receive(:purge).once end - it "busts the cache" do + it "busts the cache", :aggregate_failures do described_class.call(tag) paths.each do |path| diff --git a/spec/services/edge_cache/bust_user_spec.rb b/spec/services/edge_cache/bust_user_spec.rb index 6090ce93c62ad..a5ed7c4b908cb 100644 --- a/spec/services/edge_cache/bust_user_spec.rb +++ b/spec/services/edge_cache/bust_user_spec.rb @@ -9,12 +9,8 @@ [ "/#{username}", - "/#{username}?i=i", "/#{username}/comments", - "/#{username}/comments?i=i", - "/#{username}/comments/?i=i", "/live/#{username}", - "/live/#{username}?i=i", "/feed/#{username}", "/api/users/#{user.id}", ] @@ -28,7 +24,7 @@ end end - it "busts the cache" do + it "busts the cache", :aggregate_failures do described_class.call(user) paths.each do |path|