fix(cache): invalidate public profile cache after platform link mutations#530
Open
Ridanshi wants to merge 1 commit into
Open
fix(cache): invalidate public profile cache after platform link mutations#530Ridanshi wants to merge 1 commit into
Ridanshi wants to merge 1 commit into
Conversation
…ions 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.
|
@Ridanshi is attempting to deploy a commit to the Prashantkumar Khatri's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @Ridanshi, Thanks for opening this pull request. This PR has been automatically classified based on the files modified. Applied Labels
Primary Review Area
Reviewer@Harxhit has been identified as the primary reviewer for this pull request. If you have any questions regarding the affected area or implementation details, feel free to reach out to the assigned reviewer. Thank you for your contribution! |
CI — Checks FailedBackend — FAIL
Mobile — SKIP
Web — SKIP
Last updated: |
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.
Closes #482
Summary
This PR fixes a cache consistency issue where public profile cache entries were not invalidated after platform link mutations.
Previously, creating, updating, deleting, or reordering platform links updated the database successfully but left stale public profile data in cache until TTL expiration.
Changes
Test Coverage
Added/updated tests covering:
Result
Public profile data now stays consistent with platform link changes and visitors immediately see the latest profile state after mutations.