Skip to content

fix(chapters): cache the chapters sidebar with a 10-minute TTL - #2994

Merged
olleolleolle merged 2 commits into
codebar:masterfrom
mroderick:fix/chapters-sidebar-derived-cache-key
Oct 11, 2026
Merged

olleolleolle merged 2 commits into
codebar:masterfrom
mroderick:fix/chapters-sidebar-derived-cache-key

Conversation

@mroderick

@mroderick mroderick commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Problem: the homepage chapter list kept deactivated chapters. The sidebar fragment is cached under views/chapters_sidebar_component/chapters-sidebar, while Chapter#expire_chapters_sidebar_cache deleted chapters-sidebar. The delete never matched, so no write path invalidated the fragment, and production served one stale entry from 13 September to 7 October. Fixes #2993.

Changes:

  • Cache the sidebar under a versioned key with expires_in: 10.minutes, the shape used by the events/past fragment. Every write path, including direct database updates, shows up within the TTL. The v2 tag keeps the key clear of the stale production entry.
  • A warm cache hit runs no chapter query: the chapters relation stays lazy and the cache block never enumerates it on a hit. The request spec pins this with a zero-query assertion.
  • Remove the Chapter cache-expiry callbacks and their model specs; the TTL replaces them.

Post-deploy: no cache purge needed, and chapter changes appear within 10 minutes.

@mroderick
mroderick force-pushed the fix/chapters-sidebar-derived-cache-key branch from 6996c97 to 5ee4012 Compare October 7, 2026 19:31
@mroderick
mroderick marked this pull request as ready for review October 7, 2026 19:52
The sidebar fragment was cached under a fixed key while the Chapter
callbacks deleted a different key, so the homepage kept rendering
deactivated chapters for any write path, including direct database
updates. Cache the fragment under a versioned key with a 10-minute TTL
instead: every write path shows up within the TTL, and a warm cache hit
runs no chapter query.

Fixes codebar#2993
@mroderick
mroderick force-pushed the fix/chapters-sidebar-derived-cache-key branch from 5ee4012 to 422f380 Compare October 7, 2026 20:14
@mroderick mroderick changed the title fix(chapters): derive the sidebar cache key from the rendered chapters fix(chapters): cache the chapters sidebar with a 10-minute TTL Oct 7, 2026
@mroderick
mroderick requested a review from olleolleolle October 8, 2026 11:53

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Side-steps the "cache expiration is difficult" problem using a TTL. Good!

@olleolleolle
olleolleolle merged commit c32331f into codebar:master Oct 11, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Homepage shows deactivated chapters (sidebar fragment invalidation deletes the wrong key)

2 participants