SQLStore: Close session in withDbSession (#31775)

* SQLStore: Close session in withDbSession

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* SQLStore.WithDbSession: Never use session from context

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2021-03-18 14:27:59 +01:00
committed by GitHub
parent a2eda798e7
commit 5a0780801b
8 changed files with 116 additions and 137 deletions
+5 -13
View File
@@ -46,22 +46,14 @@ func startSession(ctx context.Context, engine *xorm.Engine, beginTran bool) (*DB
return newSess, nil
}
// WithDbSession calls the callback with an session attached to the context.
// WithDbSession calls the callback with a session.
func (ss *SQLStore) WithDbSession(ctx context.Context, callback dbTransactionFunc) error {
sess, err := startSession(ctx, ss.engine, false)
if err != nil {
return err
}
defer sess.Close()
return callback(sess)
return withDbSession(ctx, ss.engine, callback)
}
func withDbSession(ctx context.Context, callback dbTransactionFunc) error {
sess, err := startSession(ctx, x, false)
if err != nil {
return err
}
func withDbSession(ctx context.Context, engine *xorm.Engine, callback dbTransactionFunc) error {
sess := &DBSession{Session: engine.NewSession()}
defer sess.Close()
return callback(sess)
}