Add context parameter to some database functions (#26055)

To avoid deadlock problem, almost database related functions should be
have ctx as the first parameter.
This PR do a refactor for some of these functions.
This commit is contained in:
Lunny Xiao 2023-07-22 22:14:27 +08:00 committed by GitHub
parent c42b71877e
commit b167f35113
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 209 additions and 237 deletions

View file

@ -222,7 +222,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
commits := repo_module.GitToPushCommits(l)
commits.HeadCommit = repo_module.CommitToPushCommit(newCommit)
if err := issue_service.UpdateIssuesCommit(pusher, repo, commits.Commits, refName); err != nil {
if err := issue_service.UpdateIssuesCommit(ctx, pusher, repo, commits.Commits, refName); err != nil {
log.Error("updateIssuesCommit: %v", err)
}
@ -269,12 +269,12 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
}
} else {
notification.NotifyDeleteRef(ctx, pusher, repo, opts.RefFullName)
if err = pull_service.CloseBranchPulls(pusher, repo.ID, branch); err != nil {
if err = pull_service.CloseBranchPulls(ctx, pusher, repo.ID, branch); err != nil {
// close all related pulls
log.Error("close related pull request failed: %v", err)
}
if err := git_model.AddDeletedBranch(db.DefaultContext, repo.ID, branch, pusher.ID); err != nil {
if err := git_model.AddDeletedBranch(ctx, repo.ID, branch, pusher.ID); err != nil {
return fmt.Errorf("AddDeletedBranch %s:%s failed: %v", repo.FullName(), branch, err)
}
}