Commit fe45ee6
committed
fix(cache): invalidate public profile cache after platform link mutations
Root cause: createPlatformLink, updatePlatformLink, deletePlatformLink, and
reorderLinks all mutated the database but never called redis.del on the
profile:<username> cache key, leaving stale data served to viewers until
the 5-minute TTL expired naturally.
Fix: Add a private invalidateProfileCacheForUser helper that resolves the
username via a lightweight SELECT then calls redis.del. All four mutation
functions now await this helper after a successful DB write so the cache
is cleared immediately. Cache invalidation is skipped when Redis is absent
and errors are caught and logged non-fatally so a Redis blip never fails
a mutation request.
Also fix the DELETE /api/cards/:id route handler which checked error codes
as return values; the service throws errors, so the handler now catches them.
Fix cards.test.ts duplicate buildApp declaration, and apply the PlatformLink
type fix to cardService.ts (upstream/main has not yet merged that PR).
Tests: 21 new tests in profile-cache.test.ts cover cache hit/miss lifecycle,
all four mutation paths, failed mutations, non-existent links, Redis-absent
mode, consecutive mutations, cache repopulation, and non-fatal Redis errors.1 parent 8e4066e commit fe45ee6
5 files changed
Lines changed: 725 additions & 58 deletions
File tree
- apps/backend/src
- __tests__
- routes
- services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | 56 | | |
61 | 57 | | |
62 | 58 | | |
| |||
0 commit comments