Skip to content

AO3-6272 Fix chapter count caching 0 after posting draft#5833

Open
pmonfort wants to merge 1 commit into
otwcode:masterfrom
pmonfort:AO3-6272-chapter-count-zero-on-post
Open

AO3-6272 Fix chapter count caching 0 after posting draft#5833
pmonfort wants to merge 1 commit into
otwcode:masterfrom
pmonfort:AO3-6272-chapter-count-zero-on-post

Conversation

@pmonfort
Copy link
Copy Markdown
Contributor

Descripción:

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_chapters uses Rails.cache.fetch, and the block inside it queries chapters.posted.count , which in production can hit a read replica that hasn't yet received the newly posted chapter. The stale 0 gets 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 in post_draft, so number_of_posted_chapters returns 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.count to return 0 and verifying that the cached value from post_draft takes 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)

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.

1 participant