优化sql语句
This commit is contained in:
parent
357d1b468f
commit
aaa4f5e805
@ -139,16 +139,19 @@ func (s *ServerMod) SaveData() {
|
||||
log.Debug("SaveData Marshal failed,Mod Key: %s err:%v", s.key, err)
|
||||
}
|
||||
// log.Debug("SaveData Marshal success,Mod Key: %s", s.key)
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
txOptions := &sql.TxOptions{}
|
||||
tx, err := db.SqlDb.BeginTx(ctx, txOptions)
|
||||
if err != nil {
|
||||
log.Debug("SaveData sql begin tx failed,Mod Key: %s err:%v", s.key, err)
|
||||
return
|
||||
}
|
||||
err = db.SaveServerData(&DbData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
log.Debug("SaveData sql exec ,Mod Key: %s err:%v", s.key, err)
|
||||
return
|
||||
}
|
||||
tx.Commit()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user