summaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2018-12-13 23:55:43 +0800
committertechknowlogick <hello@techknowlogick.com>2018-12-13 10:55:43 -0500
commitb3b7598ec6846d53d7deb2c84781b06e22c93044 (patch)
tree53c85943b23867b20e2b31742fbe06fcda088ccd /routers/api/v1
parent49ea6e0deb7ecef327b0c2f41920f75c6aaf80d3 (diff)
downloadgitea-b3b7598ec6846d53d7deb2c84781b06e22c93044.tar.gz
gitea-b3b7598ec6846d53d7deb2c84781b06e22c93044.zip
Improve performance of dashboard (#4977)
Diffstat (limited to 'routers/api/v1')
-rw-r--r--routers/api/v1/repo/issue.go6
-rw-r--r--routers/api/v1/repo/issue_comment.go11
-rw-r--r--routers/api/v1/repo/pull.go4
3 files changed, 16 insertions, 5 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index 7a8ed09b48..65c97888f5 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -175,6 +175,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
issue := &models.Issue{
RepoID: ctx.Repo.Repository.ID,
+ Repo: ctx.Repo.Repository,
Title: form.Title,
PosterID: ctx.User.ID,
Poster: ctx.User,
@@ -212,7 +213,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
notification.NotifyNewIssue(issue)
if form.Closed {
- if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, true); err != nil {
+ if err := issue.ChangeStatus(ctx.User, true); err != nil {
if models.IsErrDependenciesLeft(err) {
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
return
@@ -273,6 +274,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
}
return
}
+ issue.Repo = ctx.Repo.Repository
if !issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWrite(models.UnitTypeIssues) {
ctx.Status(403)
@@ -333,7 +335,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
return
}
if form.State != nil {
- if err = issue.ChangeStatus(ctx.User, ctx.Repo.Repository, api.StateClosed == api.StateType(*form.State)); err != nil {
+ if err = issue.ChangeStatus(ctx.User, api.StateClosed == api.StateType(*form.State)); err != nil {
if models.IsErrDependenciesLeft(err) {
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this issue because it still has open dependencies")
return
diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go
index 3af0290585..a3fc6f41f3 100644
--- a/routers/api/v1/repo/issue_comment.go
+++ b/routers/api/v1/repo/issue_comment.go
@@ -51,7 +51,7 @@ func ListIssueComments(ctx *context.APIContext) {
}
// comments,err:=models.GetCommentsByIssueIDSince(, since)
- issue, err := models.GetRawIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
ctx.Error(500, "GetRawIssueByIndex", err)
return
@@ -68,6 +68,10 @@ func ListIssueComments(ctx *context.APIContext) {
}
apiComments := make([]*api.Comment, len(comments))
+ if err = models.CommentList(comments).LoadPosters(); err != nil {
+ ctx.Error(500, "LoadPosters", err)
+ return
+ }
for i := range comments {
apiComments[i] = comments[i].APIFormat()
}
@@ -114,6 +118,11 @@ func ListRepoIssueComments(ctx *context.APIContext) {
return
}
+ if err = models.CommentList(comments).LoadPosters(); err != nil {
+ ctx.Error(500, "LoadPosters", err)
+ return
+ }
+
apiComments := make([]*api.Comment, len(comments))
for i := range comments {
apiComments[i] = comments[i].APIFormat()
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 9fbadcd076..2ad321ea38 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -350,6 +350,7 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
pr.LoadIssue()
issue := pr.Issue
+ issue.Repo = ctx.Repo.Repository
if !issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWrite(models.UnitTypePullRequests) {
ctx.Status(403)
@@ -383,7 +384,6 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
// Send an empty array ([]) to clear all assignees from the Issue.
if ctx.Repo.CanWrite(models.UnitTypePullRequests) && (form.Assignees != nil || len(form.Assignee) > 0) {
-
err = models.UpdateAPIAssignee(issue, form.Assignee, form.Assignees, ctx.User)
if err != nil {
if models.IsErrUserNotExist(err) {
@@ -422,7 +422,7 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
return
}
if form.State != nil {
- if err = issue.ChangeStatus(ctx.User, ctx.Repo.Repository, api.StateClosed == api.StateType(*form.State)); err != nil {
+ if err = issue.ChangeStatus(ctx.User, api.StateClosed == api.StateType(*form.State)); err != nil {
if models.IsErrDependenciesLeft(err) {
ctx.Error(http.StatusPreconditionFailed, "DependenciesLeft", "cannot close this pull request because it still has open dependencies")
return