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

Improve performance of dashboard #4977

Merged
merged 10 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix bugs
  • Loading branch information
lunny committed Nov 30, 2018
commit 745d6a72e4f641efdcbf5c5eb676db03a8e982cf
8 changes: 8 additions & 0 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ func (issue *Issue) apiFormat(e Engine) *api.Issue {
}

issue.loadPoster(e)
issue.loadRepo(e)
apiIssue := &api.Issue{
ID: issue.ID,
URL: issue.APIURL(),
Expand Down Expand Up @@ -815,6 +816,10 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
return fmt.Errorf("updateIssueCols: %v", err)
}

if err = issue.loadRepo(sess); err != nil {
return fmt.Errorf("loadRepo: %v", err)
}

if _, err = createChangeTitleComment(sess, doer, issue.Repo, issue, oldTitle, title); err != nil {
return fmt.Errorf("createChangeTitleComment: %v", err)
}
Expand All @@ -825,6 +830,9 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {

mode, _ := AccessLevel(issue.Poster, issue.Repo)
if issue.IsPull {
if err = issue.loadPullRequest(sess); err != nil {
return fmt.Errorf("loadPullRequest: %v", err)
}
issue.PullRequest.Issue = issue
err = PrepareWebhooks(issue.Repo, HookEventPullRequest, &api.PullRequestPayload{
Action: api.HookIssueEdited,
Expand Down
6 changes: 6 additions & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,9 @@ func UpdateComment(doer *User, c *Comment, oldContent string) error {
UpdateIssueIndexer(c.IssueID)
}

if err := c.LoadPoster(); err != nil {
return err
}
if err := c.LoadIssue(); err != nil {
return err
}
Expand Down Expand Up @@ -1078,6 +1081,9 @@ func DeleteComment(doer *User, comment *Comment) error {
UpdateIssueIndexer(comment.IssueID)
}

if err := comment.LoadPoster(); err != nil {
return err
}
if err := comment.LoadIssue(); err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions models/issue_comment_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ func (comments CommentList) getPosterIDs() []int64 {
return keysInt64(commentIDs)
}

// LoadPosters loads posters from database
func (comments CommentList) LoadPosters() error {
return comments.loadPosters(x)
}

func (comments CommentList) loadPosters(e Engine) error {
if len(comments) == 0 {
return nil
Expand Down
4 changes: 4 additions & 0 deletions models/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func (pr *PullRequest) apiFormat(e Engine) *api.PullRequest {
headCommit *git.Commit
err error
)
if err = pr.Issue.loadRepo(e); err != nil {
log.Error(log.ERROR, "loadRepo[%d]: %v", pr.ID, err)
return nil
}
apiIssue := pr.Issue.apiFormat(e)
if pr.BaseRepo == nil {
pr.BaseRepo, err = getRepositoryByID(e, pr.BaseRepoID)
Expand Down
9 changes: 9 additions & 0 deletions routers/api/v1/repo/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
Expand Down