From 10e2f291442fdc7efc31c02f5ffcba79a36db9ac Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 14 Apr 2020 15:53:34 +0200 Subject: Cache PullRequest Divergence (#10914) * Cache PullRequest Divergence * only re-calc divergence if AddTestPullRequestTask() is exec * migrate already open pulls * finalize * take care of closed¬-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 --- services/pull/pull.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'services') 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) } }) -- cgit v1.2.3