fix: invalidate series cache when book status changes#409
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. @@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Summary
Fixes a cache invalidation bug where changing a book's status on
/books/:iddoesn't refresh the cache on the/series/:namepage, causing stale status badges and ratings to be displayed.Root Cause
The cache invalidation bug existed at two levels:
invalidateBookQueries()inuseBookStatus.tswas not invalidating series queriesSessionServiceandProgressServicewere not callingrevalidatePath('/series')Changes
3 files modified, 3 lines added:
hooks/useBookStatus.ts:57- Added series query invalidation usingqueryKeys.series.all()lib/services/session.service.ts:1365- AddedrevalidatePath('/series')lib/services/progress.service.ts:524- AddedrevalidatePath('/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 pagesrevalidatePath('/series')revalidates both/series(list) and/series/:name(detail) pagesTesting
Manual Testing
To verify the fix:
/series/Harry%20Potter)/books/:id