mirror of
https://github.com/go-gitea/gitea.git
synced 2025-10-06 00:36:28 +00:00
Use db.WithTx/WithTx2 instead of TxContext when possible (#35130)
This commit is contained in:
@@ -73,33 +73,29 @@ func increaseTasksVersionByScope(ctx context.Context, ownerID, repoID int64) err
|
||||
}
|
||||
|
||||
func IncreaseTaskVersion(ctx context.Context, ownerID, repoID int64) error {
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer committer.Close()
|
||||
|
||||
// 1. increase global
|
||||
if err := increaseTasksVersionByScope(ctx, 0, 0); err != nil {
|
||||
log.Error("IncreaseTasksVersionByScope(Global): %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// 2. increase owner
|
||||
if ownerID > 0 {
|
||||
if err := increaseTasksVersionByScope(ctx, ownerID, 0); err != nil {
|
||||
log.Error("IncreaseTasksVersionByScope(Owner): %v", err)
|
||||
return db.WithTx(ctx, func(ctx context.Context) error {
|
||||
// 1. increase global
|
||||
if err := increaseTasksVersionByScope(ctx, 0, 0); err != nil {
|
||||
log.Error("IncreaseTasksVersionByScope(Global): %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 3. increase repo
|
||||
if repoID > 0 {
|
||||
if err := increaseTasksVersionByScope(ctx, 0, repoID); err != nil {
|
||||
log.Error("IncreaseTasksVersionByScope(Repo): %v", err)
|
||||
return err
|
||||
// 2. increase owner
|
||||
if ownerID > 0 {
|
||||
if err := increaseTasksVersionByScope(ctx, ownerID, 0); err != nil {
|
||||
log.Error("IncreaseTasksVersionByScope(Owner): %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return committer.Commit()
|
||||
// 3. increase repo
|
||||
if repoID > 0 {
|
||||
if err := increaseTasksVersionByScope(ctx, 0, repoID); err != nil {
|
||||
log.Error("IncreaseTasksVersionByScope(Repo): %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user