summaryrefslogtreecommitdiffstats
path: root/models/db
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-05-03 21:46:28 +0200
committerGitHub <noreply@github.com>2022-05-03 21:46:28 +0200
commit92f139d091c906cc6d30599101d45c62a208f585 (patch)
treee7be0dfc3cd9ae0611bd7cfa11cc1ee277e756fd /models/db
parent730420b6b32414db7fcd12ede87712b0f960de7b (diff)
downloadgitea-92f139d091c906cc6d30599101d45c62a208f585.tar.gz
gitea-92f139d091c906cc6d30599101d45c62a208f585.zip
Use for a repo action one database transaction (#19576)
... more context (part of #9307)
Diffstat (limited to 'models/db')
-rw-r--r--models/db/context.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/models/db/context.go b/models/db/context.go
index 1cd23d453c..c823952cf6 100644
--- a/models/db/context.go
+++ b/models/db/context.go
@@ -103,7 +103,14 @@ func WithContext(f func(ctx *Context) error) error {
}
// WithTx represents executing database operations on a transaction
-func WithTx(f func(ctx context.Context) error) error {
+// you can optionally change the context to a parrent one
+func WithTx(f func(ctx context.Context) error, stdCtx ...context.Context) error {
+ parentCtx := DefaultContext
+ if len(stdCtx) != 0 && stdCtx[0] != nil {
+ // TODO: make sure parent context has no open session
+ parentCtx = stdCtx[0]
+ }
+
sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
@@ -111,7 +118,7 @@ func WithTx(f func(ctx context.Context) error) error {
}
if err := f(&Context{
- Context: DefaultContext,
+ Context: parentCtx,
e: sess,
}); err != nil {
return err