Skip to content

fix: filter personal comment targets before pagination - #1649

Open
lhk0504 wants to merge 1 commit into
apache:mainfrom
lhk0504:fix/personal-comment-pagination
Open

lhk0504 wants to merge 1 commit into
apache:mainfrom
lhk0504:fix/personal-comment-pagination

Conversation

@lhk0504

@lhk0504 lhk0504 commented Oct 20, 2026

Copy link
Copy Markdown

Fixes #1645

Proposed Changes

  • Resolve the distinct targets of a user's available comments and reuse SimpleObjectInfo.CheckVisibility to select the targets visible to the current viewer.
  • Apply the visible target IDs to the comment query before pagination and counting. In the reported A/B/C example, page 1 now contains C with count: 1, and page 2 is empty with count: 1.
  • Reuse the resolved object information when building the response. Existing comment-page callers remain unrestricted when the object-ID filter is nil, while an empty filter returns no comments.
  • Add real SQLite regression tests covering pagination, repeated targets, user and comment-status isolation, empty and missing targets, question and answer ownership, moderator access, hidden parent questions, closed questions, and tag targets.

Validation

Passed locally:

  • go test ./internal/service/comment ./internal/repo/repo_test -count=1 (SQLite)
  • go build ./...
  • go vet ./...
  • golangci-lint run ./internal/service/comment/... ./internal/repo/comment/... ./internal/repo/repo_test/...
  • git diff --check

The new service regression tests were also run against the old implementation and reproduced the incorrect counts and pagination.

MySQL/PostgreSQL tests were not run because the local Docker socket is inaccessible.

Trade-off

Each request checks all distinct comment targets for the profile user before querying the requested page. Request cost and the size of the SQL IN filter therefore grow with the number of distinct targets; large-scale performance has not been benchmarked.

Related: #1648 proposes another fix for the same issue.

This branch has not been deployed

No deployments
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.

Personal comments can return empty pages and incorrect counts after visibility filtering

1 participant