summaryrefslogtreecommitdiffstats
path: root/models/pull.go
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 /models/pull.go
parent49ea6e0deb7ecef327b0c2f41920f75c6aaf80d3 (diff)
downloadgitea-b3b7598ec6846d53d7deb2c84781b06e22c93044.tar.gz
gitea-b3b7598ec6846d53d7deb2c84781b06e22c93044.zip
Improve performance of dashboard (#4977)
Diffstat (limited to 'models/pull.go')
-rw-r--r--models/pull.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/models/pull.go b/models/pull.go
index 0041f83dc8..0d8886186e 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -148,6 +148,10 @@ 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
@@ -155,16 +159,20 @@ func (pr *PullRequest) APIFormat() *api.PullRequest {
headCommit *git.Commit
err error
)
- apiIssue := pr.Issue.APIFormat()
+ 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(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
@@ -187,15 +195,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,
@@ -542,7 +553,7 @@ func (pr *PullRequest) setMerged() (err error) {
return err
}
- if err = pr.Issue.changeStatus(sess, pr.Merger, pr.Issue.Repo, true); err != nil {
+ if err = pr.Issue.changeStatus(sess, pr.Merger, true); err != nil {
return fmt.Errorf("Issue.changeStatus: %v", err)
}
if _, err = sess.ID(pr.ID).Cols("has_merged, status, merged_commit_id, merger_id, merged_unix").Update(pr); err != nil {