From bbc0a5b4b9803ad2fbfd6b83e114532d714502fe Mon Sep 17 00:00:00 2001 From: weeklies <80141759+weeklies@users.noreply.github.com> Date: Fri, 18 Aug 2023 11:04:23 +0800 Subject: [PATCH] AO3-5052 Delete cached series byline when updating pseud or username (#4609) AO3-5052-spr Change how series byline expiration works --- app/models/pseud.rb | 2 +- app/models/series.rb | 6 ++++++ app/models/user.rb | 2 +- spec/models/pseud_spec.rb | 14 -------------- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/app/models/pseud.rb b/app/models/pseud.rb index 550ed3dc963..5ce87de8f96 100644 --- a/app/models/pseud.rb +++ b/app/models/pseud.rb @@ -400,7 +400,7 @@ def check_default_pseud def expire_caches if saved_change_to_name? works.touch_all - series.touch_all + series.each(&:expire_byline_cache) end end diff --git a/app/models/series.rb b/app/models/series.rb index b31714c7c1c..5daecb15bcd 100644 --- a/app/models/series.rb +++ b/app/models/series.rb @@ -150,6 +150,12 @@ def expire_caches self.works.each(&:touch) if saved_change_to_title? end + def expire_byline_cache + [true, false].each do |only_path| + Rails.cache.delete("#{cache_key}/byline-nonanon/#{only_path}") + end + end + # Change the positions of the serial works in the series def reorder_list(positions) SortableList.new(self.serial_works.in_order).reorder_list(positions) diff --git a/app/models/user.rb b/app/models/user.rb index f33abd06949..6d51edcd8db 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -158,7 +158,7 @@ class User < ApplicationRecord def expire_caches return unless saved_change_to_login? - series.touch_all + series.each(&:expire_byline_cache) self.works.each do |work| work.touch work.expire_caches diff --git a/spec/models/pseud_spec.rb b/spec/models/pseud_spec.rb index c8b5ade0d80..eac4a07b777 100644 --- a/spec/models/pseud_spec.rb +++ b/spec/models/pseud_spec.rb @@ -66,20 +66,6 @@ end end - describe "expire_caches" do - let(:pseud) { create(:pseud) } - let(:series) { create(:series, authors: [pseud]) } - - it "modifies the updated_at of associated series" do - pseud.reload - series.reload - travel(1.day) - expect do - pseud.update(name: "New Name") - end.to change { series.reload.updated_at } - end - end - describe ".default_alphabetical" do let(:user) { create(:user, login: "Zaphod") } let(:subject) { user.pseuds.default_alphabetical }