Skip to content

Commit

Permalink
AO3-5052 Delete cached series byline when updating pseud or username (#…
Browse files Browse the repository at this point in the history
…4609)

AO3-5052-spr Change how series byline expiration works
  • Loading branch information
weeklies committed Aug 19, 2023
1 parent f53d29d commit bbc0a5b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/models/pseud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions app/models/series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions spec/models/pseud_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit bbc0a5b

Please sign in to comment.