diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-11-12 21:18:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-12 21:18:50 +0100 |
commit | 34283a74e85278fed2c9b70d6f8749dc6a4001ca (patch) | |
tree | f8fa43399cb723d55efc34dacf7947faf0ed5acf /services/issue | |
parent | Add some documentation to packages (#21648) (diff) | |
download | forgejo-34283a74e85278fed2c9b70d6f8749dc6a4001ca.tar.xz forgejo-34283a74e85278fed2c9b70d6f8749dc6a4001ca.zip |
Allow detect whether it's in a database transaction for a context.Context (#21756)
Fix #19513
This PR introduce a new db method `InTransaction(context.Context)`,
and also builtin check on `db.TxContext` and `db.WithTx`.
There is also a new method `db.AutoTx` has been introduced but could be used by other PRs.
`WithTx` will always open a new transaction, if a transaction exist in context, return an error.
`AutoTx` will try to open a new transaction if no transaction exist in context.
That means it will always enter a transaction if there is no error.
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'services/issue')
-rw-r--r-- | services/issue/issue.go | 2 | ||||
-rw-r--r-- | services/issue/label.go | 2 | ||||
-rw-r--r-- | services/issue/milestone.go | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/services/issue/issue.go b/services/issue/issue.go index 47782e50d3..8342d7f5d2 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -209,7 +209,7 @@ func GetRefEndNamesAndURLs(issues []*issues_model.Issue, repoLink string) (map[i // deleteIssue deletes the issue func deleteIssue(issue *issues_model.Issue) error { - ctx, committer, err := db.TxContext() + ctx, committer, err := db.TxContext(db.DefaultContext) if err != nil { return err } diff --git a/services/issue/label.go b/services/issue/label.go index bc5f9b910e..a9a0c20b01 100644 --- a/services/issue/label.go +++ b/services/issue/label.go @@ -45,7 +45,7 @@ func AddLabels(issue *issues_model.Issue, doer *user_model.User, labels []*issue // RemoveLabel removes a label from issue by given ID. func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error { - ctx, committer, err := db.TxContext() + ctx, committer, err := db.TxContext(db.DefaultContext) if err != nil { return err } diff --git a/services/issue/milestone.go b/services/issue/milestone.go index 756a8625de..965b07556d 100644 --- a/services/issue/milestone.go +++ b/services/issue/milestone.go @@ -65,7 +65,7 @@ func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *is // ChangeMilestoneAssign changes assignment of milestone for issue. func ChangeMilestoneAssign(issue *issues_model.Issue, doer *user_model.User, oldMilestoneID int64) (err error) { - ctx, committer, err := db.TxContext() + ctx, committer, err := db.TxContext(db.DefaultContext) if err != nil { return err } |