1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Use for a repo action one database transaction (#19576)

... more context

(part of #9307)
This commit is contained in:
6543
2022-05-03 21:46:28 +02:00
committed by GitHub
parent 730420b6b3
commit 92f139d091
29 changed files with 270 additions and 260 deletions

View File

@@ -5,6 +5,8 @@
package issue
import (
"context"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
@@ -14,10 +16,16 @@ import (
// ChangeStatus changes issue status to open or closed.
func ChangeStatus(issue *models.Issue, doer *user_model.User, closed bool) error {
comment, err := models.ChangeIssueStatus(issue, doer, closed)
return changeStatusCtx(db.DefaultContext, issue, doer, closed)
}
// changeStatusCtx changes issue status to open or closed.
// TODO: if context is not db.DefaultContext we get a deadlock!!!
func changeStatusCtx(ctx context.Context, issue *models.Issue, doer *user_model.User, closed bool) error {
comment, err := models.ChangeIssueStatus(ctx, issue, doer, closed)
if err != nil {
if models.IsErrDependenciesLeft(err) && closed {
if err := models.FinishIssueStopwatchIfPossible(db.DefaultContext, doer, issue); err != nil {
if err := models.FinishIssueStopwatchIfPossible(ctx, doer, issue); err != nil {
log.Error("Unable to stop stopwatch for issue[%d]#%d: %v", issue.ID, issue.Index, err)
}
}
@@ -25,7 +33,7 @@ func ChangeStatus(issue *models.Issue, doer *user_model.User, closed bool) error
}
if closed {
if err := models.FinishIssueStopwatchIfPossible(db.DefaultContext, doer, issue); err != nil {
if err := models.FinishIssueStopwatchIfPossible(ctx, doer, issue); err != nil {
return err
}
}