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 panic
  • Loading branch information
lunny committed Nov 30, 2018
commit 25bb1c2a4ec405dcad9ee1a1371f172f49b89bf9
13 changes: 8 additions & 5 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func (issue *Issue) HTMLURL() string {
} else {
path = "issues"
}
issue.loadRepo(x)
return fmt.Sprintf("%s/%s/%d", issue.Repo.HTMLURL(), path, issue.Index)
}

Expand Down Expand Up @@ -322,13 +321,17 @@ func (issue *Issue) State() api.StateType {
// Required - Poster, Labels,
// Optional - Milestone, Assignee, PullRequest
func (issue *Issue) APIFormat() *api.Issue {
issue.loadLabels(x)
return issue.apiFormat(x)
}

func (issue *Issue) apiFormat(e Engine) *api.Issue {
issue.loadLabels(e)
apiLabels := make([]*api.Label, len(issue.Labels))
for i := range issue.Labels {
apiLabels[i] = issue.Labels[i].APIFormat()
}

issue.loadPoster(x)
issue.loadPoster(e)
apiIssue := &api.Issue{
ID: issue.ID,
URL: issue.APIURL(),
Expand All @@ -346,7 +349,7 @@ func (issue *Issue) APIFormat() *api.Issue {
if issue.Milestone != nil {
apiIssue.Milestone = issue.Milestone.APIFormat()
}
issue.loadAssignees(x)
issue.loadAssignees(e)

if len(issue.Assignees) > 0 {
for _, assignee := range issue.Assignees {
Expand All @@ -355,7 +358,7 @@ func (issue *Issue) APIFormat() *api.Issue {
apiIssue.Assignee = issue.Assignees[0].APIFormat() // For compatibility, we're keeping the first assignee as `apiIssue.Assignee`
}
if issue.IsPull {
issue.loadPullRequest(x)
issue.loadPullRequest(e)
apiIssue.PullRequest = &api.PullRequestMeta{
HasMerged: issue.PullRequest.HasMerged,
}
Expand Down
6 changes: 3 additions & 3 deletions models/issue_assignees.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (issue *Issue) changeAssignee(sess *xorm.Session, doer *User, assigneeID in
apiPullRequest := &api.PullRequestPayload{
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
Repository: issue.Repo.APIFormat(mode),
Repository: issue.Repo.innerAPIFormat(sess, mode, false),
Sender: doer.APIFormat(),
}
if removed {
Expand All @@ -191,8 +191,8 @@ func (issue *Issue) changeAssignee(sess *xorm.Session, doer *User, assigneeID in

apiIssue := &api.IssuePayload{
Index: issue.Index,
Issue: issue.APIFormat(),
Repository: issue.Repo.APIFormat(mode),
Issue: issue.apiFormat(sess),
Repository: issue.Repo.innerAPIFormat(sess, mode, false),
Sender: doer.APIFormat(),
}
if removed {
Expand Down
17 changes: 12 additions & 5 deletions models/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,27 @@ func (pr *PullRequest) GetGitRefName() string {
// Required - Issue
// Optional - Merger
func (pr *PullRequest) APIFormat() *api.PullRequest {
return pr.apiFormat(x)
}

func (pr *PullRequest) apiFormat(e Engine) *api.PullRequest {
var (
baseBranch *Branch
headBranch *Branch
baseCommit *git.Commit
headCommit *git.Commit
err error
)
apiIssue := pr.Issue.APIFormat()
apiIssue := pr.Issue.apiFormat(e)
if pr.BaseRepo == nil {
pr.BaseRepo, err = GetRepositoryByID(pr.BaseRepoID)
pr.BaseRepo, err = getRepositoryByID(e, pr.BaseRepoID)
if err != nil {
log.Error(log.ERROR, "GetRepositoryById[%d]: %v", pr.ID, err)
return nil
}
}
if pr.HeadRepo == nil {
pr.HeadRepo, err = GetRepositoryByID(pr.HeadRepoID)
pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID)
if err != nil {
log.Error(log.ERROR, "GetRepositoryById[%d]: %v", pr.ID, err)
return nil
Expand All @@ -180,15 +184,18 @@ func (pr *PullRequest) APIFormat() *api.PullRequest {
Ref: pr.BaseBranch,
Sha: baseCommit.ID.String(),
RepoID: pr.BaseRepoID,
Repository: pr.BaseRepo.APIFormat(AccessModeNone),
Repository: pr.BaseRepo.innerAPIFormat(e, AccessModeNone, false),
}
apiHeadBranchInfo := &api.PRBranchInfo{
Name: pr.HeadBranch,
Ref: pr.HeadBranch,
Sha: headCommit.ID.String(),
RepoID: pr.HeadRepoID,
Repository: pr.HeadRepo.APIFormat(AccessModeNone),
Repository: pr.HeadRepo.innerAPIFormat(e, AccessModeNone, false),
}

pr.Issue.loadRepo(e)

apiPullRequest := &api.PullRequest{
ID: pr.ID,
Index: pr.Index,
Expand Down