Skip to content

AO3-4250 Made gift recipients update on blurbs on pseud / username changes - #5063

Closed
melinath wants to merge 5 commits into
otwcode:masterfrom
melinath:AO3-4250
Closed

AO3-4250 Made gift recipients update on blurbs on pseud / username changes#5063
melinath wants to merge 5 commits into
otwcode:masterfrom
melinath:AO3-4250

Conversation

@melinath

Copy link
Copy Markdown
Contributor

Pull Request Checklist

Issue

https://otwarchive.atlassian.net/browse/AO3-4250

Purpose

Made it so that changing a pseud or username, deleting a pseud, or deleting a user account will expire the cache for all gift works (so that the byline will no longer display the old pseud or username.)

For deleting a pseud, this is done by expiring the cache on all gifts for the default pseud (since gifts are reassigned to the default pseud.) This will clear more caches than necessary - technically we only need to expire the cache for the gifts that were previously assigned to pseud being deleted. I did it this way for now because it's easier & keeps all the code in one place, which I think is easier to understand / less likely to break; however, I can definitely go back and change this if desired.

I also tweaked some of the tests related to series blurb updates (to ensure that they behave properly if only the username is updated and no pseuds) and fixed some minor whitespace issues on adjacent tests.

Credit

Stephen Lewis, he/him

Comment thread app/models/pseud.rb
Comment on lines +400 to 407
pseud.works.each do |work|
work.touch
work.expire_caches
end
pseud.gift_works.each do |work|
work.touch
work.expire_caches
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The discussion whether touching the works is the right cache busting strategy hasn't quite concluded, but it looks like we were leaning towards it. So, this can be optimized further.

For the gift works, the information is in the blurb. The blurb cache key depends on the work cache key, which depends on the work's updated_at. So it's enough to touch the work to bust the cache, no need to manually do so via expire_caches. That means that this can use the more optimised touch_all instead of looping through the gift works.

Your PR doesn't say why you updated pseud.works to use expire_caches as well, but I think it should be fine to go back to touch_all in this case too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now the discussion looks to be concluded, we'll go with touching things synchronously for the time being

Comment thread app/models/pseud.rb

after_update :check_default_pseud
after_update :expire_caches
after_destroy :expire_caches

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already have a check for saved_change_to_name?, could this be moved to after_commit to avoid duplicating with both after_update and after_destroy?

Comment on lines +219 to +224
Given I have no users
And the following activated users exist
| login | password | email | id |
| gifter | something | gifter@example.com | 1 |
| giftee1 | something | giftee1@example.com | 2 |
And a pseud exists with name: "Me2", user_id: 2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this and the following tests, could you use

When /^"([^\"]*)" creates the default pseud "([^"]*)"$/ do |username, newpseud|
to avoid hardcoding user IDs? Then, we should be able to drop the Given I have no users and remove the ID column from the next step

@Bilka2

Bilka2 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Adopted at #5967 based on the policy for stalled pull requests

@Bilka2 Bilka2 closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants