From c6c30d58abbd1ae2d0d6f6049b1ca5b202d49a04 Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Fri, 18 Mar 2022 09:10:43 -0500 Subject: [PATCH] Remove fastly http purge feature flag and conditional behavior (#16903) * Always use purge, never post, to fastly * Remove unneeded feature flag --- app/services/edge_cache/bust/fastly.rb | 10 +-------- ...317151317_remove_fastly_http_purge_flag.rb | 7 +++++++ .../remove_fastly_http_purge_flag_spec.rb | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 lib/data_update_scripts/20220317151317_remove_fastly_http_purge_flag.rb create mode 100644 spec/lib/data_update_scripts/remove_fastly_http_purge_flag_spec.rb diff --git a/app/services/edge_cache/bust/fastly.rb b/app/services/edge_cache/bust/fastly.rb index ed7f055a1..3b4985e58 100644 --- a/app/services/edge_cache/bust/fastly.rb +++ b/app/services/edge_cache/bust/fastly.rb @@ -4,18 +4,10 @@ module EdgeCache # [@forem/systems] Fastly-enabled Forems don't need "flexible" domains. def self.call(path) api_key = ApplicationConfig["FASTLY_API_KEY"] - return fastly_purge(api_key, path) if FeatureFlag.enabled?(:fastly_http_purge) - fastly_post(api_key, path) + fastly_purge(api_key, path) end - def self.fastly_post(api_key, path) - urls(path).map do |url| - HTTParty.post("https://api.fastly.com/purge/#{url}", headers: { "Fastly-Key" => api_key }) - end - end - private_class_method :fastly_post - def self.fastly_purge(api_key, path) fastly = ::Fastly.new(api_key: api_key) diff --git a/lib/data_update_scripts/20220317151317_remove_fastly_http_purge_flag.rb b/lib/data_update_scripts/20220317151317_remove_fastly_http_purge_flag.rb new file mode 100644 index 000000000..19a64227a --- /dev/null +++ b/lib/data_update_scripts/20220317151317_remove_fastly_http_purge_flag.rb @@ -0,0 +1,7 @@ +module DataUpdateScripts + class RemoveFastlyHttpPurgeFlag + def run + FeatureFlag.remove(:fastly_http_purge) + end + end +end diff --git a/spec/lib/data_update_scripts/remove_fastly_http_purge_flag_spec.rb b/spec/lib/data_update_scripts/remove_fastly_http_purge_flag_spec.rb new file mode 100644 index 000000000..a6e55144f --- /dev/null +++ b/spec/lib/data_update_scripts/remove_fastly_http_purge_flag_spec.rb @@ -0,0 +1,21 @@ +require "rails_helper" +require Rails.root.join( + "lib/data_update_scripts/20220317151317_remove_fastly_http_purge_flag.rb", +) + +describe DataUpdateScripts::RemoveFastlyHttpPurgeFlag do + it "removes the feature flag if present" do + FeatureFlag.add(:fastly_http_purge) + + described_class.new.run + + expect(FeatureFlag.exist?(:fastly_http_purge)).to be false + end + + it "is safe to run twice" do + # this is the same as "does nothing if flag not present" + 2.times { described_class.new.run } + + expect(FeatureFlag.exist?(:fastly_http_purge)).to be false + end +end