Skip to content

Commit 0f3923c

Browse files
authored
fix potential lock when sqlite (#1647)
1 parent b6206e4 commit 0f3923c

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

models/pull.go

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,29 +1058,30 @@ func (pr *PullRequest) checkAndUpdateStatus() {
10581058
// TODO: test more pull requests at same time.
10591059
func TestPullRequests() {
10601060
prs := make([]*PullRequest, 0, 10)
1061-
x.Iterate(PullRequest{
1062-
Status: PullRequestStatusChecking,
1063-
},
1064-
func(idx int, bean interface{}) error {
1065-
pr := bean.(*PullRequest)
1066-
1067-
if err := pr.GetBaseRepo(); err != nil {
1068-
log.Error(3, "GetBaseRepo: %v", err)
1069-
return nil
1070-
}
1071-
if pr.manuallyMerged() {
1072-
return nil
1073-
}
1074-
if err := pr.testPatch(); err != nil {
1075-
log.Error(3, "testPatch: %v", err)
1076-
return nil
1077-
}
1078-
prs = append(prs, pr)
1079-
return nil
1080-
})
1061+
1062+
err := x.Where("status = ?", PullRequestStatusChecking).Find(&prs)
1063+
if err != nil {
1064+
log.Error(3, "Find Checking PRs", err)
1065+
return
1066+
}
1067+
1068+
var checkedPRs = make(map[int64]struct{})
10811069

10821070
// Update pull request status.
10831071
for _, pr := range prs {
1072+
checkedPRs[pr.ID] = struct{}{}
1073+
if err := pr.GetBaseRepo(); err != nil {
1074+
log.Error(3, "GetBaseRepo: %v", err)
1075+
continue
1076+
}
1077+
if pr.manuallyMerged() {
1078+
continue
1079+
}
1080+
if err := pr.testPatch(); err != nil {
1081+
log.Error(3, "testPatch: %v", err)
1082+
continue
1083+
}
1084+
10841085
pr.checkAndUpdateStatus()
10851086
}
10861087

@@ -1089,7 +1090,12 @@ func TestPullRequests() {
10891090
log.Trace("TestPullRequests[%v]: processing test task", prID)
10901091
pullRequestQueue.Remove(prID)
10911092

1092-
pr, err := GetPullRequestByID(com.StrTo(prID).MustInt64())
1093+
id := com.StrTo(prID).MustInt64()
1094+
if _, ok := checkedPRs[id]; ok {
1095+
continue
1096+
}
1097+
1098+
pr, err := GetPullRequestByID(id)
10931099
if err != nil {
10941100
log.Error(4, "GetPullRequestByID[%s]: %v", prID, err)
10951101
continue

0 commit comments

Comments
 (0)