Repository navigation
Keep each user's vote in the last comments response - #2263
Merged
Merged
Conversation
The last comments response carries the requesting user's own vote on each comment, but its cache key did not include the user, so the first requester's votes could be served to other readers until the next flush. A vote never triggered that flush either, so the voter kept seeing the state from before the vote. The response is now cached per user, as the comment listing is. A vote flushes a scope that only this response carries, so the site and reply feeds, which show no votes, stay cached.
There was a problem hiding this comment.
🟢 Approval recommended
The cache-key and invalidation changes are consistent and comprehensively covered by the regression test.
0 open findings
What changed in this PR
Caches /api/v1/last responses per user and invalidates vote-bearing responses without flushing RSS feeds.
Changes:
- Adds a dedicated cache scope for last-comment votes.
- Uses user-aware cache keys and flushes vote caches after voting.
- Adds comprehensive LRU-cache regression coverage.
| File | Description |
|---|---|
backend/app/rest/api/rest.go |
Defines the vote-specific cache scope. |
backend/app/rest/api/rest_public.go |
Makes last-comment caching user-specific. |
backend/app/rest/api/rest_public_test.go |
Tests isolation and invalidation behavior. |
backend/app/rest/api/rest_private.go |
Invalidates last-comment vote caches after voting. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
CI installs the newest Go 1.27 patch release, now 1.27.2, and golangci-lint v2.13.2 cannot read its export data, so the lint step failed with an export data decoding error. v2.14.0, built with Go 1.27.1, reports no issues in backend/app and backend/_example/memory_store under Go 1.27.2.
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.
Previously, the
/api/v1/lastcache key did not include the user, although the response carries the requesting user's own vote on each comment. The first requester's votes could be served to other readers until the cache was flushed, and a vote never flushed it, so the voter kept seeing the state from before the vote.After this change, the response is cached per user, as the comment listing already is. A vote flushes a scope that only this response carries, so the site and reply RSS feeds, which show no votes, stay cached.
TestRest_LastVoteIsPerUserruns against a real LRU cache and fails if the per-user key, the vote flush, the separate scope, or the existing comment-scope refresh is reverted.