From 8598ed090e42a5ffab07cb0daa485a7ff0960a8f Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 9 Dec 2020 10:37:02 -0500 Subject: [PATCH] Create services for busting pages, tags, events, and podcasts (#11812) * Create bust_page service and spec * Specify spec with .once * Create bust_tag service and spec * Create bust_event service and spec * Create bust_podcast service and spec --- app/services/edge_cache/bust_events.rb | 8 +++++ app/services/edge_cache/bust_page.rb | 12 +++++++ app/services/edge_cache/bust_podcast.rb | 9 ++++++ app/services/edge_cache/bust_tag.rb | 15 +++++++++ spec/services/edge_cache/bust_events_spec.rb | 24 ++++++++++++++ spec/services/edge_cache/bust_page_spec.rb | 27 ++++++++++++++++ spec/services/edge_cache/bust_podcast_spec.rb | 24 ++++++++++++++ spec/services/edge_cache/bust_tag_spec.rb | 32 +++++++++++++++++++ 8 files changed, 151 insertions(+) create mode 100644 app/services/edge_cache/bust_events.rb create mode 100644 app/services/edge_cache/bust_page.rb create mode 100644 app/services/edge_cache/bust_podcast.rb create mode 100644 app/services/edge_cache/bust_tag.rb create mode 100644 spec/services/edge_cache/bust_events_spec.rb create mode 100644 spec/services/edge_cache/bust_page_spec.rb create mode 100644 spec/services/edge_cache/bust_podcast_spec.rb create mode 100644 spec/services/edge_cache/bust_tag_spec.rb diff --git a/app/services/edge_cache/bust_events.rb b/app/services/edge_cache/bust_events.rb new file mode 100644 index 000000000..1165560e3 --- /dev/null +++ b/app/services/edge_cache/bust_events.rb @@ -0,0 +1,8 @@ +module EdgeCache + class BustEvents < Bust + def self.call + bust("/events") + bust("/events?i=i") + end + end +end diff --git a/app/services/edge_cache/bust_page.rb b/app/services/edge_cache/bust_page.rb new file mode 100644 index 000000000..35370a76a --- /dev/null +++ b/app/services/edge_cache/bust_page.rb @@ -0,0 +1,12 @@ +module EdgeCache + class BustPage < Bust + def self.call(slug) + return unless slug + + bust("/page/#{slug}") + bust("/page/#{slug}?i=i") + bust("/#{slug}") + bust("/#{slug}?i=i") + end + end +end diff --git a/app/services/edge_cache/bust_podcast.rb b/app/services/edge_cache/bust_podcast.rb new file mode 100644 index 000000000..a00e68e23 --- /dev/null +++ b/app/services/edge_cache/bust_podcast.rb @@ -0,0 +1,9 @@ +module EdgeCache + class BustPodcast < Bust + def self.call(path) + return unless path + + bust("/#{path}") + end + end +end diff --git a/app/services/edge_cache/bust_tag.rb b/app/services/edge_cache/bust_tag.rb new file mode 100644 index 000000000..c881f591a --- /dev/null +++ b/app/services/edge_cache/bust_tag.rb @@ -0,0 +1,15 @@ +module EdgeCache + class BustTag < Bust + def self.call(tag) + return unless tag + + tag.purge + + bust("/t/#{tag.name}") + bust("/t/#{tag.name}?i=i") + bust("/t/#{tag.name}/?i=i") + bust("/t/#{tag.name}/") + bust("/tags") + end + end +end diff --git a/spec/services/edge_cache/bust_events_spec.rb b/spec/services/edge_cache/bust_events_spec.rb new file mode 100644 index 000000000..64b4ba91f --- /dev/null +++ b/spec/services/edge_cache/bust_events_spec.rb @@ -0,0 +1,24 @@ +require "rails_helper" + +RSpec.describe EdgeCache::BustEvents, type: :service do + let(:paths) do + [ + "/events", + "/events?i=i", + ] + end + + before do + paths.each do |path| + allow(described_class).to receive(:bust).with(path).once + end + end + + it "busts the cache" do + described_class.call + + paths.each do |path| + expect(described_class).to have_received(:bust).with(path).once + end + end +end diff --git a/spec/services/edge_cache/bust_page_spec.rb b/spec/services/edge_cache/bust_page_spec.rb new file mode 100644 index 000000000..f8d02e98d --- /dev/null +++ b/spec/services/edge_cache/bust_page_spec.rb @@ -0,0 +1,27 @@ +require "rails_helper" + +RSpec.describe EdgeCache::BustPage, type: :service do + let(:slug) { "slug" } + let(:paths) do + [ + "/page/#{slug}", + "/page/#{slug}?i=i", + "/#{slug}", + "/#{slug}?i=i", + ] + end + + before do + paths.each do |path| + allow(described_class).to receive(:bust).with(path).once + end + end + + it "busts the cache" do + described_class.call(slug) + + paths.each do |path| + expect(described_class).to have_received(:bust).with(path).once + end + end +end diff --git a/spec/services/edge_cache/bust_podcast_spec.rb b/spec/services/edge_cache/bust_podcast_spec.rb new file mode 100644 index 000000000..4df4ad89e --- /dev/null +++ b/spec/services/edge_cache/bust_podcast_spec.rb @@ -0,0 +1,24 @@ +require "rails_helper" + +RSpec.describe EdgeCache::BustPodcast, type: :service do + let(:podcast_path) { "podcast_path" } + let(:paths) do + [ + "/#{podcast_path}", + ] + end + + before do + paths.each do |path| + allow(described_class).to receive(:bust).with(path).once + end + end + + it "busts the cache" do + described_class.call(podcast_path) + + paths.each do |path| + expect(described_class).to have_received(:bust).with(path).once + end + end +end diff --git a/spec/services/edge_cache/bust_tag_spec.rb b/spec/services/edge_cache/bust_tag_spec.rb new file mode 100644 index 000000000..f315b0004 --- /dev/null +++ b/spec/services/edge_cache/bust_tag_spec.rb @@ -0,0 +1,32 @@ +require "rails_helper" + +RSpec.describe EdgeCache::BustTag, type: :service do + let(:tag) { create(:tag) } + let(:paths) do + [ + "/t/#{tag.name}", + "/t/#{tag.name}?i=i", + "/t/#{tag.name}/?i=i", + "/t/#{tag.name}/", + "/tags", + ] + end + + before do + paths.each do |path| + allow(described_class).to receive(:bust).with(path).once + end + + allow(tag).to receive(:purge).once + end + + it "busts the cache" do + described_class.call(tag) + + paths.each do |path| + expect(described_class).to have_received(:bust).with(path).once + end + + expect(tag).to have_received(:purge).once + end +end