Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CommentList instead of []*Comment #24828

Merged
merged 2 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/issues/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ func (opts *FindCommentsOptions) ToConds() builder.Cond {
}

// FindComments returns all comments according options
func FindComments(ctx context.Context, opts *FindCommentsOptions) ([]*Comment, error) {
func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList, error) {
comments := make([]*Comment, 0, 10)
sess := db.GetEngine(ctx).Where(opts.ToConds())
if opts.RepoID > 0 {
Expand Down
4 changes: 2 additions & 2 deletions models/issues/comment_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *u
}

func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issue, currentUser *user_model.User, review *Review) ([]*Comment, error) {
var comments []*Comment
var comments CommentList
if review == nil {
review = &Review{ID: 0}
}
Expand All @@ -68,7 +68,7 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
return nil, err
}

if err := CommentList(comments).LoadPosters(ctx); err != nil {
if err := comments.LoadPosters(ctx); err != nil {
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions models/issues/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type Issue struct {
ClosedUnix timeutil.TimeStamp `xorm:"INDEX"`

Attachments []*repo_model.Attachment `xorm:"-"`
Comments []*Comment `xorm:"-"`
Comments CommentList `xorm:"-"`
Reactions ReactionList `xorm:"-"`
TotalTrackedTime int64 `xorm:"-"`
Assignees []*user_model.User `xorm:"-"`
Expand Down Expand Up @@ -353,7 +353,7 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) {
return err
}

if err = CommentList(issue.Comments).loadAttributes(ctx); err != nil {
if err = issue.Comments.loadAttributes(ctx); err != nil {
return err
}
if issue.IsTimetrackerEnabled(ctx) {
Expand Down
16 changes: 8 additions & 8 deletions routers/api/v1/repo/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ func ListIssueComments(ctx *context.APIContext) {
return
}

if err := issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
if err := comments.LoadPosters(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}

if err := issues_model.CommentList(comments).LoadAttachments(ctx); err != nil {
if err := comments.LoadAttachments(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadAttachments", err)
return
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
return
}

if err := issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
if err := comments.LoadPosters(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}
Expand Down Expand Up @@ -285,25 +285,25 @@ func ListRepoIssueComments(ctx *context.APIContext) {
return
}

if err = issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
if err = comments.LoadPosters(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}

apiComments := make([]*api.Comment, len(comments))
if err := issues_model.CommentList(comments).LoadIssues(ctx); err != nil {
if err := comments.LoadIssues(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadIssues", err)
return
}
if err := issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
if err := comments.LoadPosters(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}
if err := issues_model.CommentList(comments).LoadAttachments(ctx); err != nil {
if err := comments.LoadAttachments(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadAttachments", err)
return
}
if _, err := issues_model.CommentList(comments).Issues().LoadRepositories(ctx); err != nil {
if _, err := comments.Issues().LoadRepositories(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadRepositories", err)
return
}
Expand Down