mirror of
https://github.com/go-gitea/gitea.git
synced 2026-12-04 15:54:57 +00:00
fix(api): exclude code comments from the timeline query, not after paging (#40511)
The issue timeline API paged the comment query and then dropped code comments from the page, so pages could come back short or empty while later pages still held events, and clients that stop at such a page missed them. Code comments are now excluded in the query itself. Comments the doer cannot read are still filtered after paging, and `X-Total-Count` still reflects the page length. Both are left for a follow-up. Independent of https://github.com/go-gitea/gitea/pull/40496 and https://github.com/go-gitea/gitea/pull/40497. Refs: https://github.com/go-gitea/gitea/issues/40495 Assisted-by: Claude:claude-opus-5-5 --------- Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
1 parent
933ab82a16
commit
eddd00278b
3 files changed
+31
-20
No files matched your search
+15
-11
@@ -1111,17 +1111,18 @@ func GetCommentWithRepoID(ctx context.Context, repoID, commentID int64) (*Commen
|
||||
// FindCommentsOptions describes the conditions to Find comments
|
||||
type FindCommentsOptions struct {
|
||||
db.ListOptions
|
||||
RepoID int64
|
||||
IssueID int64
|
||||
ReviewID int64
|
||||
Since int64
|
||||
Before int64
|
||||
Line int64
|
||||
TreePath string
|
||||
Type CommentType
|
||||
IssueIDs []int64
|
||||
Invalidated optional.Option[bool]
|
||||
IsPull optional.Option[bool]
|
||||
RepoID int64
|
||||
IssueID int64
|
||||
ReviewID int64
|
||||
Since int64
|
||||
Before int64
|
||||
Line int64
|
||||
TreePath string
|
||||
Type CommentType
|
||||
ExcludeTypes []CommentType
|
||||
IssueIDs []int64
|
||||
Invalidated optional.Option[bool]
|
||||
IsPull optional.Option[bool]
|
||||
}
|
||||
|
||||
func (opts FindCommentsOptions) ToOrders() string {
|
||||
@@ -1151,6 +1152,9 @@ func (opts FindCommentsOptions) ToConds() builder.Cond {
|
||||
if opts.Type != CommentTypeUndefined {
|
||||
cond = cond.And(builder.Eq{"comment.type": opts.Type})
|
||||
}
|
||||
if len(opts.ExcludeTypes) > 0 {
|
||||
cond = cond.And(builder.NotIn("comment.type", opts.ExcludeTypes))
|
||||
}
|
||||
if opts.Line != 0 {
|
||||
cond = cond.And(builder.Eq{"comment.line": opts.Line})
|
||||
}
|
||||
|
||||
@@ -169,11 +169,12 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
|
||||
}
|
||||
|
||||
opts := &issues_model.FindCommentsOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
IssueID: issue.ID,
|
||||
Since: since,
|
||||
Before: before,
|
||||
Type: issues_model.CommentTypeUndefined,
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
IssueID: issue.ID,
|
||||
Since: since,
|
||||
Before: before,
|
||||
Type: issues_model.CommentTypeUndefined,
|
||||
ExcludeTypes: []issues_model.CommentType{issues_model.CommentTypeCode},
|
||||
}
|
||||
|
||||
comments, err := issues_model.FindComments(ctx, opts)
|
||||
@@ -193,10 +194,8 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
|
||||
|
||||
var apiComments []*api.TimelineComment
|
||||
for _, comment := range comments {
|
||||
if comment.Type != issues_model.CommentTypeCode {
|
||||
comment.Issue = issue
|
||||
apiComments = append(apiComments, convert.ToTimelineComment(ctx, issue.Repo, comment, ctx.Doer))
|
||||
}
|
||||
comment.Issue = issue
|
||||
apiComments = append(apiComments, convert.ToTimelineComment(ctx, issue.Repo, comment, ctx.Doer))
|
||||
}
|
||||
|
||||
ctx.SetTotalCountHeader(int64(len(apiComments)))
|
||||
|
||||
@@ -123,6 +123,14 @@ func TestAPIComments(t *testing.T) {
|
||||
comments := DecodeJSON(t, resp, []*api.TimelineComment{})
|
||||
expectedCount := unittest.GetCount(t, &issues_model.Comment{IssueID: issue.ID})
|
||||
assert.Len(t, comments, expectedCount)
|
||||
|
||||
req = NewRequest(t, "GET", "/api/v1/repos/user2/repo1/issues/3/timeline?limit=2")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
comments = DecodeJSON(t, resp, []*api.TimelineComment{})
|
||||
if assert.Len(t, comments, 2) {
|
||||
assert.EqualValues(t, 10, comments[0].ID)
|
||||
assert.EqualValues(t, 11, comments[1].ID)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("GetSystemUserComment", func(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user