Skip to content

Keep each user's vote in the last comments response - #2263

Merged
umputun merged 2 commits into
masterfrom
fix-last-comments-cache
Oct 11, 2026
Merged

umputun merged 2 commits into
masterfrom
fix-last-comments-cache

Conversation

@paskal

@paskal paskal commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Previously, the /api/v1/last cache 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_LastVoteIsPerUser runs 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.

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.
@paskal
paskal requested a review from umputun as a code owner October 11, 2026 06:06
Copilot AI balanced review requested due to automatic review settings October 11, 2026 06:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@umputun
umputun merged commit 7a61e0a into master Oct 11, 2026
9 checks passed
@umputun
umputun deleted the fix-last-comments-cache branch October 11, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants