fix(cache): separate viewer-specific follow state from cached public profiles#531
Open
Ridanshi wants to merge 1 commit into
Open
fix(cache): separate viewer-specific follow state from cached public profiles#531Ridanshi wants to merge 1 commit into
Ridanshi wants to merge 1 commit into
Conversation
…e cache Previously, getPublicProfile stored the full response (including `followed` state for the request's viewer) directly in Redis. On cache HIT, every subsequent viewer received the follow state of whoever populated the cache — causing incorrect followed=false or followed=true for all links regardless of the actual viewer's follow history. Fix: cache entries now store only viewer-independent fields (id, platform, username, url, displayOrder). The `followed` field is excluded from the cache. On every request — HIT or MISS — follow state is computed fresh from followLog for the authenticated viewer, then merged into the response before returning. Also stores `_userId` in the cache entry so background view-tracking can fire on cache-HIT requests without an extra DB round-trip, while ensuring `_userId` is stripped from all HTTP responses. Add comprehensive tests covering: - Cache population writes shared-only data (no `followed` field) - Cache HIT returns X-Cache: HIT and skips DB query - Authenticated viewer on HIT triggers fresh followLog query - Anonymous request on HIT skips followLog query - Viewer A and Viewer B receive different follow states from same cached entry - Cache entry bytes are identical regardless of which viewer triggered population - Viewer A's follow state does not bleed into Viewer B's response - Follow/unfollow with warm cache returns correct state immediately - Regression: 404, 200, Cache-Control, Redis fallback all intact
|
@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 — All Checks PassedBackend — PASS
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 #483
Summary
This PR fixes a cache contamination issue where viewer-specific follow state was being stored inside cached public profile responses.
As a result, authenticated users could receive incorrect follow indicators when cached profile data was served.
Changes
Test Coverage
Added/updated tests covering:
Result
Public profile caching remains efficient while authenticated users always receive accurate follow-state information regardless of cache status.