Skip to content

fix: invalidate series cache when book status changes#409

Merged
masonfox merged 1 commit intodevelopfrom
fix/series-cache-invalidation
Mar 31, 2026
Merged

fix: invalidate series cache when book status changes#409
masonfox merged 1 commit intodevelopfrom
fix/series-cache-invalidation

Conversation

@masonfox
Copy link
Copy Markdown
Owner

Summary

Fixes a cache invalidation bug where changing a book's status on /books/:id doesn't refresh the cache on the /series/:name page, causing stale status badges and ratings to be displayed.

Root Cause

The cache invalidation bug existed at two levels:

  1. Client-Side (React Query): invalidateBookQueries() in useBookStatus.ts was not invalidating series queries
  2. Server-Side (Next.js): SessionService and ProgressService were not calling revalidatePath('/series')

Changes

3 files modified, 3 lines added:

  • hooks/useBookStatus.ts:57 - Added series query invalidation using queryKeys.series.all()
  • lib/services/session.service.ts:1365 - Added revalidatePath('/series')
  • lib/services/progress.service.ts:524 - Added revalidatePath('/series')

Implementation Details

The fix uses "nuclear" invalidation (invalidate all series queries) for simplicity and reliability, consistent with the existing shelf invalidation pattern when specific targeting is complex.

  • queryKeys.series.all() returns ['series'], which matches both series list and all series detail pages
  • revalidatePath('/series') revalidates both /series (list) and /series/:name (detail) pages

Testing

  • ✅ All 4,013 tests pass (188 test files)
  • ✅ No regressions detected
  • ✅ Changes follow existing patterns

Manual Testing

To verify the fix:

  1. Open a series detail page (e.g., /series/Harry%20Potter)
  2. Note a book's status badge
  3. Change that book's status on /books/:id
  4. Return to the series page - status should now update immediately

When a book's status is changed on /books/:id, the series detail page
at /series/:name was not being invalidated, causing stale data to be
displayed (incorrect status badges and ratings).

This fix adds series cache invalidation at two levels:

1. Client-side (React Query): invalidateBookQueries() now invalidates
   all series queries using queryKeys.series.all()

2. Server-side (Next.js): SessionService and ProgressService now call
   revalidatePath('/series') to revalidate series pages

The fix uses 'nuclear' invalidation (invalidate all series queries)
for simplicity and reliability, consistent with the existing shelf
invalidation pattern when specific targeting is complex.

All 4,013 tests pass with no regressions.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #409   +/-   ##
========================================
  Coverage    78.66%   78.67%           
========================================
  Files          167      167           
  Lines         7556     7559    +3     
  Branches      1850     1850           
========================================
+ Hits          5944     5947    +3     
  Misses        1127     1127           
  Partials       485      485           
Flag Coverage Δ
unittests 78.67% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
hooks/useBookStatus.ts 85.62% <100.00%> (+0.09%) ⬆️
lib/services/progress.service.ts 87.60% <100.00%> (+0.10%) ⬆️
lib/services/session.service.ts 88.18% <100.00%> (+0.03%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@masonfox masonfox merged commit f7dff99 into develop Mar 31, 2026
4 checks passed
@masonfox masonfox deleted the fix/series-cache-invalidation branch March 31, 2026 18:24
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.

1 participant