Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-5052 Delete cached series byline when updating pseud or username #4609

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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