forked from forgejo/forgejo
Use for a repo action one database transaction (#19576)
... more context (part of #9307)
This commit is contained in:
parent
730420b6b3
commit
92f139d091
29 changed files with 270 additions and 260 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue