From eca7be820109ff897b22ebcf0f046564d4ca7054 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 29 Dec 2020 03:53:00 -0500 Subject: [PATCH] Update bust_user to EdgeCache::BustUser (#12051) --- app/controllers/organizations_controller.rb | 2 +- app/services/users/delete_articles.rb | 4 ++-- app/services/users/delete_comments.rb | 4 ++-- ...01026155851_resave_to_bust_cache_for_imgproxy.rb | 2 +- spec/services/users/delete_articles_spec.rb | 8 +++----- spec/services/users/delete_comments_spec.rb | 13 ++++++------- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index f2404b4f2..e08004088 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -53,7 +53,7 @@ class OrganizationsController < ApplicationController authorize organization if organization.destroy current_user.touch(:organization_info_updated_at) - CacheBuster.bust_user(current_user) + EdgeCache::BustUser.call(current_user) flash[:settings_notice] = "Your organization: \"#{organization.name}\" was successfully deleted." redirect_to user_settings_path(:organization) else diff --git a/app/services/users/delete_articles.rb b/app/services/users/delete_articles.rb index d3b2c4f7c..41b5ef2fc 100644 --- a/app/services/users/delete_articles.rb +++ b/app/services/users/delete_articles.rb @@ -2,7 +2,7 @@ module Users module DeleteArticles module_function - def call(user, cache_buster = CacheBuster) + def call(user) return if user.articles.blank? virtual_articles = user.articles.map { |article| Article.new(article.attributes) } @@ -12,7 +12,7 @@ module Users article.comments.includes(:user).find_each do |comment| comment.reactions.delete_all EdgeCache::BustComment.call(comment.commentable) - cache_buster.bust_user(comment.user) + EdgeCache::BustUser.call(comment.user) comment.remove_from_elasticsearch comment.delete end diff --git a/app/services/users/delete_comments.rb b/app/services/users/delete_comments.rb index 60480f324..7659dfc77 100644 --- a/app/services/users/delete_comments.rb +++ b/app/services/users/delete_comments.rb @@ -2,7 +2,7 @@ module Users module DeleteComments module_function - def call(user, cache_buster = CacheBuster) + def call(user) return unless user.comments.any? user.comments.find_each do |comment| @@ -12,7 +12,7 @@ module Users comment.remove_from_elasticsearch comment.delete end - cache_buster.bust_user(user) + EdgeCache::BustUser.call(user) end end end diff --git a/lib/data_update_scripts/20201026155851_resave_to_bust_cache_for_imgproxy.rb b/lib/data_update_scripts/20201026155851_resave_to_bust_cache_for_imgproxy.rb index a97e56cc6..3de90c4e9 100644 --- a/lib/data_update_scripts/20201026155851_resave_to_bust_cache_for_imgproxy.rb +++ b/lib/data_update_scripts/20201026155851_resave_to_bust_cache_for_imgproxy.rb @@ -4,7 +4,7 @@ module DataUpdateScripts return unless ENV["FOREM_CONTEXT"] == "forem_cloud" User.find_each do |user| - CacheBuster.bust_user(user) + EdgeCache::BustUser.call(user) end Organization.find_each do |organization| diff --git a/spec/services/users/delete_articles_spec.rb b/spec/services/users/delete_articles_spec.rb index 1817209da..6805f23db 100644 --- a/spec/services/users/delete_articles_spec.rb +++ b/spec/services/users/delete_articles_spec.rb @@ -23,12 +23,10 @@ RSpec.describe Users::DeleteArticles, type: :service do end context "with comments" do - let(:buster) { double } - before do allow(EdgeCache::BustComment).to receive(:call) allow(EdgeCache::BustArticle).to receive(:call) - allow(buster).to receive(:bust_user) + allow(EdgeCache::BustUser).to receive(:call) create_list(:comment, 2, commentable: article, user: user2) end @@ -47,9 +45,9 @@ RSpec.describe Users::DeleteArticles, type: :service do end it "busts cache" do - described_class.call(user, buster) + described_class.call(user) expect(EdgeCache::BustComment).to have_received(:call).with(article).twice - expect(buster).to have_received(:bust_user).with(user2).at_least(:once) + expect(EdgeCache::BustUser).to have_received(:call).with(user2).at_least(:once) expect(EdgeCache::BustArticle).to have_received(:call).with(article) end diff --git a/spec/services/users/delete_comments_spec.rb b/spec/services/users/delete_comments_spec.rb index cccb9a55b..9d1090f8b 100644 --- a/spec/services/users/delete_comments_spec.rb +++ b/spec/services/users/delete_comments_spec.rb @@ -5,18 +5,17 @@ RSpec.describe Users::DeleteComments, type: :service do let(:trusted_user) { create(:user, :trusted) } let(:article) { create(:article) } let(:comment) { create(:comment, user: user, commentable: article) } - let(:buster) { double } before do create_list(:comment, 2, commentable: article, user: user) allow(EdgeCache::BustComment).to receive(:call) - allow(buster).to receive(:bust_user) + allow(EdgeCache::BustUser).to receive(:call) end it "destroys user comments" do comment - described_class.call(user, buster) + described_class.call(user) expect(Comment.where(user_id: user.id).any?).to be false end @@ -24,19 +23,19 @@ RSpec.describe Users::DeleteComments, type: :service do comment sidekiq_perform_enqueued_jobs expect(comment.elasticsearch_doc).not_to be_nil - sidekiq_perform_enqueued_jobs { described_class.call(user, buster) } + sidekiq_perform_enqueued_jobs { described_class.call(user) } expect { comment.elasticsearch_doc }.to raise_error(Search::Errors::Transport::NotFound) end it "busts cache" do - described_class.call(user, buster) + described_class.call(user) expect(EdgeCache::BustComment).to have_received(:call).with(article).at_least(:once) - expect(buster).to have_received(:bust_user).with(user) + expect(EdgeCache::BustUser).to have_received(:call).with(user) end it "destroys moderation notifications properly" do create(:notification, notifiable: comment, action: "Moderation", user: trusted_user) - described_class.call(user, buster) + described_class.call(user) expect(Notification.count).to eq 0 end end