diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2018-12-13 23:55:43 +0800 |
---|---|---|
committer | techknowlogick <hello@techknowlogick.com> | 2018-12-13 10:55:43 -0500 |
commit | b3b7598ec6846d53d7deb2c84781b06e22c93044 (patch) | |
tree | 53c85943b23867b20e2b31742fbe06fcda088ccd /routers | |
parent | 49ea6e0deb7ecef327b0c2f41920f75c6aaf80d3 (diff) | |
download | gitea-b3b7598ec6846d53d7deb2c84781b06e22c93044.tar.gz gitea-b3b7598ec6846d53d7deb2c84781b06e22c93044.zip |
Improve performance of dashboard (#4977)
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue.go | 6 | ||||
-rw-r--r-- | routers/api/v1/repo/issue_comment.go | 11 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 4 | ||||
-rw-r--r-- | routers/repo/issue.go | 25 | ||||
-rw-r--r-- | routers/repo/pull.go | 44 | ||||
-rw-r--r-- | routers/user/home.go | 1 |
6 files changed, 62 insertions, 29 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 diff --git a/routers/repo/issue.go b/routers/repo/issue.go index e0fb4ac52f..3600120fb5 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -576,6 +576,12 @@ func ViewIssue(ctx *context.Context) { ctx.Data["RequireTribute"] = true renderAttachmentSettings(ctx) + err = issue.LoadAttributes() + if err != nil { + ctx.ServerError("GetIssueByIndex", err) + return + } + ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title) var iw *models.IssueWatch @@ -677,6 +683,10 @@ func ViewIssue(ctx *context.Context) { ctx.ServerError("GetIssueByID", err) return } + if err = otherIssue.LoadRepo(); err != nil { + ctx.ServerError("LoadRepo", err) + return + } // Add link to the issue of the already running stopwatch ctx.Data["OtherStopwatchURL"] = otherIssue.HTMLURL() } @@ -697,7 +707,17 @@ func ViewIssue(ctx *context.Context) { // Render comments and and fetch participants. participants[0] = issue.Poster for _, comment = range issue.Comments { + if err := comment.LoadPoster(); err != nil { + ctx.ServerError("LoadPoster", err) + return + } + if comment.Type == models.CommentTypeComment { + if err := comment.LoadAttachments(); err != nil { + ctx.ServerError("LoadAttachments", err) + return + } + comment.RenderedContent = string(markdown.Render([]byte(comment.Content), ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())) @@ -868,6 +888,7 @@ func GetActionIssue(ctx *context.Context) *models.Issue { ctx.NotFoundOrServerError("GetIssueByIndex", models.IsErrIssueNotExist, err) return nil } + issue.Repo = ctx.Repo.Repository checkIssueRights(ctx, issue) if ctx.Written() { return nil @@ -1049,7 +1070,7 @@ func UpdateIssueStatus(ctx *context.Context) { } for _, issue := range issues { if issue.IsClosed != isClosed { - if err := issue.ChangeStatus(ctx.User, issue.Repo, isClosed); err != nil { + if err := issue.ChangeStatus(ctx.User, isClosed); err != nil { if models.IsErrDependenciesLeft(err) { ctx.JSON(http.StatusPreconditionFailed, map[string]interface{}{ "error": "cannot close this issue because it still has open dependencies", @@ -1126,7 +1147,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) { ctx.Flash.Info(ctx.Tr("repo.pulls.open_unmerged_pull_exists", pr.Index)) } else { isClosed := form.Status == "close" - if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, isClosed); err != nil { + if err := issue.ChangeStatus(ctx.User, isClosed); err != nil { log.Error(4, "ChangeStatus: %v", err) if models.IsErrDependenciesLeft(err) { diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 4adfb96e74..0d5cec802c 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -223,6 +223,10 @@ func checkPullInfo(ctx *context.Context) *models.Issue { } return nil } + if err = issue.LoadPoster(); err != nil { + ctx.ServerError("LoadPoster", err) + return nil + } ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title) ctx.Data["Issue"] = issue @@ -231,6 +235,11 @@ func checkPullInfo(ctx *context.Context) *models.Issue { return nil } + if err = issue.LoadPullRequest(); err != nil { + ctx.ServerError("LoadPullRequest", err) + return nil + } + if err = issue.PullRequest.GetHeadRepo(); err != nil { ctx.ServerError("GetHeadRepo", err) return nil @@ -519,16 +528,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) { return } - pr, err := models.GetPullRequestByIssueID(issue.ID) - if err != nil { - if models.IsErrPullRequestNotExist(err) { - ctx.NotFound("GetPullRequestByIssueID", nil) - } else { - ctx.ServerError("GetPullRequestByIssueID", err) - } - return - } - pr.Issue = issue + pr := issue.PullRequest if !pr.CanAutoMerge() || pr.HasMerged { ctx.NotFound("MergePullRequest", nil) @@ -949,15 +949,7 @@ func CleanUpPullRequest(ctx *context.Context) { return } - pr, err := models.GetPullRequestByIssueID(issue.ID) - if err != nil { - if models.IsErrPullRequestNotExist(err) { - ctx.NotFound("GetPullRequestByIssueID", nil) - } else { - ctx.ServerError("GetPullRequestByIssueID", err) - } - return - } + pr := issue.PullRequest // Allow cleanup only for merged PR if !pr.HasMerged { @@ -965,7 +957,7 @@ func CleanUpPullRequest(ctx *context.Context) { return } - if err = pr.GetHeadRepo(); err != nil { + if err := pr.GetHeadRepo(); err != nil { ctx.ServerError("GetHeadRepo", err) return } else if pr.HeadRepo == nil { @@ -1077,8 +1069,12 @@ func DownloadPullDiff(ctx *context.Context) { return } - pr := issue.PullRequest + if err = issue.LoadPullRequest(); err != nil { + ctx.ServerError("LoadPullRequest", err) + return + } + pr := issue.PullRequest if err = pr.GetBaseRepo(); err != nil { ctx.ServerError("GetBaseRepo", err) return @@ -1111,8 +1107,12 @@ func DownloadPullPatch(ctx *context.Context) { return } - pr := issue.PullRequest + if err = issue.LoadPullRequest(); err != nil { + ctx.ServerError("LoadPullRequest", err) + return + } + pr := issue.PullRequest if err = pr.GetHeadRepo(); err != nil { ctx.ServerError("GetHeadRepo", err) return diff --git a/routers/user/home.go b/routers/user/home.go index 4c6a9f6cd0..883adf4e6c 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -138,6 +138,7 @@ func Dashboard(ctx *context.Context) { OnlyPerformedBy: false, IncludeDeleted: false, }) + if ctx.Written() { return } |