summaryrefslogtreecommitdiffstats
path: root/services/org
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-11-12 21:18:50 +0100
committerGitHub <noreply@github.com>2022-11-12 21:18:50 +0100
commit34283a74e85278fed2c9b70d6f8749dc6a4001ca (patch)
treef8fa43399cb723d55efc34dacf7947faf0ed5acf /services/org
parentAdd some documentation to packages (#21648) (diff)
downloadforgejo-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/org')
-rw-r--r--services/org/org.go2
-rw-r--r--services/org/repo.go2
2 files changed, 2 insertions, 2 deletions
diff --git a/services/org/org.go b/services/org/org.go
index 39845610d2..d993f82bbf 100644
--- a/services/org/org.go
+++ b/services/org/org.go
@@ -19,7 +19,7 @@ import (
// DeleteOrganization completely and permanently deletes everything of organization.
func DeleteOrganization(org *organization.Organization) error {
- ctx, commiter, err := db.TxContext()
+ ctx, commiter, err := db.TxContext(db.DefaultContext)
if err != nil {
return err
}
diff --git a/services/org/repo.go b/services/org/repo.go
index 769419d45b..88520c819f 100644
--- a/services/org/repo.go
+++ b/services/org/repo.go
@@ -22,7 +22,7 @@ func TeamAddRepository(t *organization.Team, repo *repo_model.Repository) (err e
return nil
}
- return db.WithTx(func(ctx context.Context) error {
+ return db.WithTx(db.DefaultContext, func(ctx context.Context) error {
return models.AddRepository(ctx, t, repo)
})
}