-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Cache PullRequest Divergence #10914
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
Merged
techknowlogick
merged 30 commits into
go-gitea:master
from
6543-forks:cache-pr-GetDiverging
Apr 14, 2020
Merged
Cache PullRequest Divergence #10914
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
45b5aa0
Cache PullRequest Divergence
6543 3d2ca63
only re-calc divergence if AddTestPullRequestTask() is exec
6543 1f7effe
migrate already open pulls
6543 846c924
finalize
6543 870cda8
take care of closed¬-merged+deleted-branch pull requests
6543 cd34286
fix nil pointer exeption
6543 6e27c62
try this
6543 235f1e4
no error its a warn
6543 f2e0536
Merge branch 'master' into cache-pr-GetDiverging
6543 39e12ba
init gitea-repositories-meta
6543 faceafd
Merge branch 'master' into cache-pr-GetDiverging
6543 059f5b0
Merge branch 'master' into cache-pr-GetDiverging
6543 a8e3c4b
Merge branch 'master' into cache-pr-GetDiverging
6543 9c5dd2f
Merge branch 'master' into cache-pr-GetDiverging
6543 0f12098
dont use gitDivergence type
6543 04d785e
Merge branch 'master' into cache-pr-GetDiverging
6543 fe503ef
CI.restart()
6543 b65da30
CI.restart()
6543 4bbaf98
Merge branch 'master' into cache-pr-GetDiverging
6543 fb468a5
Merge branch 'master' into cache-pr-GetDiverging
6543 2819468
Merge branch 'master' into cache-pr-GetDiverging
6543 bbbafea
Merge branch 'master' into cache-pr-GetDiverging
6543 4407fe3
Merge branch 'master' into cache-pr-GetDiverging
6543 20a262a
Merge branch 'master' into cache-pr-GetDiverging
6543 40e7cb1
Merge branch 'master' into cache-pr-GetDiverging
6543 e8d6720
CI.restart()
6543 0894c42
CI.restart()
6543 d086468
Merge branch 'master' into cache-pr-GetDiverging
6543 13440b2
check IsUserAllowedToUpdate independend from CommitsBehind
6543 c1f0b04
Merge branch 'master' into cache-pr-GetDiverging
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
|
||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/setting" | ||
pull_service "code.gitea.io/gitea/services/pull" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
func addCommitDivergenceToPulls(x *xorm.Engine) error { | ||
|
||
if err := x.Sync2(new(models.PullRequest)); err != nil { | ||
return fmt.Errorf("Sync2: %v", err) | ||
} | ||
|
||
var last int | ||
batchSize := setting.Database.IterateBufferSize | ||
sess := x.NewSession() | ||
defer sess.Close() | ||
for { | ||
if err := sess.Begin(); err != nil { | ||
return err | ||
} | ||
var results = make([]*models.PullRequest, 0, batchSize) | ||
err := sess.Where("has_merged = ?", false).OrderBy("id").Limit(batchSize, last).Find(&results) | ||
if err != nil { | ||
return err | ||
} | ||
if len(results) == 0 { | ||
break | ||
} | ||
last += len(results) | ||
|
||
for _, pr := range results { | ||
divergence, err := pull_service.GetDiverging(pr) | ||
if err != nil { | ||
if err = pr.LoadIssue(); err != nil { | ||
return fmt.Errorf("pr.LoadIssue()[%d]: %v", pr.ID, err) | ||
} | ||
if !pr.Issue.IsClosed { | ||
return fmt.Errorf("GetDiverging: %v", err) | ||
} | ||
log.Warn("Could not recalculate Divergence for pull: %d", pr.ID) | ||
pr.CommitsAhead = 0 | ||
pr.CommitsBehind = 0 | ||
} | ||
if divergence != nil { | ||
pr.CommitsAhead = divergence.Ahead | ||
pr.CommitsBehind = divergence.Behind | ||
} | ||
if _, err = sess.ID(pr.ID).Cols("commits_ahead", "commits_behind").Update(pr); err != nil { | ||
return fmt.Errorf("Update Cols: %v", err) | ||
} | ||
} | ||
|
||
if err := sess.Commit(); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.