AO3-6272 Fix chapter count caching 0 after posting draft#5833
Open
pmonfort wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Descripción:
AO3-1234 Fix thing)Issue
https://otwarchive.atlassian.net/browse/AO3-6272
Purpose
When posting a work from draft, the chapter count sometimes displays "0/1" instead of "1/1". This happens because
number_of_posted_chaptersusesRails.cache.fetch, and the block inside it querieschapters.posted.count, which in production can hit a read replica that hasn't yet received the newly posted chapter. The stale0gets cached, and subsequent reads return the wrong count until the cache expires.This PR writes the correct chapter count (
1) directly to the cache immediately after saving inpost_draft, sonumber_of_posted_chaptersreturns the cached value instead of querying a potentially stale replica.Testing Instructions
This bug is not reproducible locally (no read replicas in development). The automated test simulates the stale replica by stubbing
chapters.posted.countto return 0 and verifying that the cached value frompost_drafttakes precedence.References
Related to AO3-6273 (word count blank after posting), which has a similar production environment but a different root cause.
Credit
Pablo Monfort (he/him)