Fix stale food entry delete cache - #1103
Conversation
|
Storybook previews for This comment updates automatically on each PR push. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/server/src/routers/food.ts`:
- Around line 47-50: invalidateFoodCaches currently lets cache-invalidation
failures propagate and can turn successful DB commits into client-visible
errors; wrap the invalidation calls (queryCache.invalidateByPrefix in
invalidateFoodCaches) in a try/catch that calls captureException(err) and logs
the error (e.g., processLogger.error) but does NOT rethrow, ensuring the
mutation callers (where invalidateFoodCaches is invoked after DB commits) always
return success when the DB write succeeded; alternatively, move the try/catch
into each caller after the DB commit and call captureException on any failure
while allowing the original success response to be returned.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 997a3ddb-0b96-467b-9b0d-c5e4961cb327
📒 Files selected for processing (2)
packages/server/src/routers/food.integration.test.tspackages/server/src/routers/food.ts
There was a problem hiding this comment.
Pull request overview
This PR addresses stale food/nutrition query results by invalidating relevant tRPC query caches after food mutations, and adds an integration test to prevent regressions where cached food.byDate data can mask a deletion.
Changes:
- Add
invalidateFoodCaches()and call it afterfood.create,food.update,food.delete, andfood.quickAddmutations. - Add an integration regression test ensuring
food.byDatereturns fresh data after deleting an entry that was previously loaded (and thus potentially cached).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/server/src/routers/food.ts | Introduces a helper to invalidate food/nutrition cache prefixes and calls it after food write mutations. |
| packages/server/src/routers/food.integration.test.ts | Adds a regression test covering deletion after an initial cached byDate read. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Review app is ready: This environment runs on a dedicated Hetzner server for PR #1103 and updates on each push. |
Summary
Tests
Note: pnpm test ran 10,612 passing tests but exited nonzero locally because two integration suites hit the known Testcontainers startup error
No host port found for host IPunder high load. Both affected suites passed when rerun in isolation.Summary by CodeRabbit
Tests
Bug Fixes