summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-04-14 15:53:34 +0200
committerGitHub <noreply@github.com>2020-04-14 09:53:34 -0400
commit10e2f291442fdc7efc31c02f5ffcba79a36db9ac (patch)
tree5dbda60a983caf8d83ad7202755587acd692c212 /services
parentc571c5bb286b925297f4eb32d130a5496126c3cb (diff)
downloadgitea-10e2f291442fdc7efc31c02f5ffcba79a36db9ac.tar.gz
gitea-10e2f291442fdc7efc31c02f5ffcba79a36db9ac.zip
Cache PullRequest Divergence (#10914)
* Cache PullRequest Divergence * only re-calc divergence if AddTestPullRequestTask() is exec * migrate already open pulls * finalize * take care of closed&not-merged+deleted-branch pull requests * fix nil pointer exeption Signed-off-by: 6543 <6543@obermui.de> * try this * no error its a warn * init gitea-repositories-meta * dont use gitDivergence type * CI.restart() * CI.restart() * CI.restart() * CI.restart() * check IsUserAllowedToUpdate independend from CommitsBehind
Diffstat (limited to 'services')
-rw-r--r--services/pull/pull.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 2797294980..fb4af06372 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -31,6 +31,13 @@ func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int6
return err
}
+ divergence, err := GetDiverging(pr)
+ if err != nil {
+ return err
+ }
+ pr.CommitsAhead = divergence.Ahead
+ pr.CommitsBehind = divergence.Behind
+
if err := models.NewPullRequest(repo, pull, labelIDs, uuids, pr); err != nil {
return err
}
@@ -212,6 +219,15 @@ func AddTestPullRequestTask(doer *models.User, repoID int64, branch string, isSy
if err := models.MarkReviewsAsNotStale(pr.IssueID, newCommitID); err != nil {
log.Error("MarkReviewsAsNotStale: %v", err)
}
+ divergence, err := GetDiverging(pr)
+ if err != nil {
+ log.Error("GetDiverging: %v", err)
+ } else {
+ err = pr.UpdateCommitDivergence(divergence.Ahead, divergence.Behind)
+ if err != nil {
+ log.Error("UpdateCommitDivergence: %v", err)
+ }
+ }
}
pr.Issue.PullRequest = pr
@@ -229,6 +245,15 @@ func AddTestPullRequestTask(doer *models.User, repoID int64, branch string, isSy
return
}
for _, pr := range prs {
+ divergence, err := GetDiverging(pr)
+ if err != nil {
+ log.Error("GetDiverging: %v", err)
+ } else {
+ err = pr.UpdateCommitDivergence(divergence.Ahead, divergence.Behind)
+ if err != nil {
+ log.Error("UpdateCommitDivergence: %v", err)
+ }
+ }
AddToTaskQueue(pr)
}
})