mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Improve performance of dashboard (#4977)
This commit is contained in:
committed by
techknowlogick
parent
49ea6e0deb
commit
b3b7598ec6
@@ -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
|
||||
|
@@ -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()
|
||||
|
@@ -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
|
||||
|
@@ -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) {
|
||||
|
@@ -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
|
||||
|
@@ -138,6 +138,7 @@ func Dashboard(ctx *context.Context) {
|
||||
OnlyPerformedBy: false,
|
||||
IncludeDeleted: false,
|
||||
})
|
||||
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user