summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-04-18 13:00:03 +0800
committertechknowlogick <matti@mdranta.net>2019-04-18 01:00:03 -0400
commitdd1acd7ce4b4afc5d1c803f85767def242a899bb (patch)
tree785f7698189353f46af91352fb71a086f2080968 /routers
parent2262811e407facea09047e94aa1850c192511587 (diff)
downloadgitea-dd1acd7ce4b4afc5d1c803f85767def242a899bb.tar.gz
gitea-dd1acd7ce4b4afc5d1c803f85767def242a899bb.zip
Comments list performance optimization (#5305)
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/issue_comment.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go
index fd085b66bc..7a720deab2 100644
--- a/routers/api/v1/repo/issue_comment.go
+++ b/routers/api/v1/repo/issue_comment.go
@@ -57,6 +57,7 @@ func ListIssueComments(ctx *context.APIContext) {
ctx.Error(500, "GetRawIssueByIndex", err)
return
}
+ issue.Repo = ctx.Repo.Repository
comments, err := models.FindComments(models.FindCommentsOptions{
IssueID: issue.ID,
@@ -64,16 +65,18 @@ func ListIssueComments(ctx *context.APIContext) {
Type: models.CommentTypeComment,
})
if err != nil {
- ctx.Error(500, "GetCommentsByIssueIDSince", err)
+ ctx.Error(500, "FindComments", err)
return
}
- apiComments := make([]*api.Comment, len(comments))
- if err = models.CommentList(comments).LoadPosters(); err != nil {
+ if err := models.CommentList(comments).LoadPosters(); err != nil {
ctx.Error(500, "LoadPosters", err)
return
}
- for i := range comments {
+
+ apiComments := make([]*api.Comment, len(comments))
+ for i, comment := range comments {
+ comment.Issue = issue
apiComments[i] = comments[i].APIFormat()
}
ctx.JSON(200, &apiComments)
@@ -115,7 +118,7 @@ func ListRepoIssueComments(ctx *context.APIContext) {
Type: models.CommentTypeComment,
})
if err != nil {
- ctx.Error(500, "GetCommentsByRepoIDSince", err)
+ ctx.Error(500, "FindComments", err)
return
}
@@ -125,6 +128,18 @@ func ListRepoIssueComments(ctx *context.APIContext) {
}
apiComments := make([]*api.Comment, len(comments))
+ if err := models.CommentList(comments).LoadIssues(); err != nil {
+ ctx.Error(500, "LoadIssues", err)
+ return
+ }
+ if err := models.CommentList(comments).LoadPosters(); err != nil {
+ ctx.Error(500, "LoadPosters", err)
+ return
+ }
+ if _, err := models.CommentList(comments).Issues().LoadRepositories(); err != nil {
+ ctx.Error(500, "LoadRepositories", err)
+ return
+ }
for i := range comments {
apiComments[i] = comments[i].APIFormat()
}