This commit is contained in:
苏尹岚
2021-03-31 15:37:59 +08:00
parent ebb7424282
commit 423c1f8845
2 changed files with 39 additions and 16 deletions

View File

@@ -784,12 +784,12 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, upcs []str
} }
var tmpList []*tGetStoresSkusInfo var tmpList []*tGetStoresSkusInfo
beginTime := time.Now() beginTime := time.Now()
if err = dao.GetRows(db, &tmpList, sql, sqlParams...); err != nil { if err = dao.GetRowsTx(txDB, &tmpList, sql, sqlParams...); err != nil {
dao.Rollback(db, txDB) dao.Rollback(db, txDB)
return nil, err return nil, err
} }
if isBySku { if isBySku {
skuNamesInfo.TotalCount = dao.GetLastTotalRowCount(db) skuNamesInfo.TotalCount = dao.GetLastTotalRowCount2(db, txDB)
} }
dao.Commit(db, txDB) dao.Commit(db, txDB)
globals.SugarLogger.Debugf("GetStoresSkusNew get result2:%v", time.Now().Sub(beginTime)) globals.SugarLogger.Debugf("GetStoresSkusNew get result2:%v", time.Now().Sub(beginTime))

View File

@@ -147,6 +147,15 @@ func GetRows(db *DaoDB, inPtr interface{}, sql string, values ...interface{}) (e
return err return err
} }
func GetRowsTx(txDB orm.TxOrmer, inPtr interface{}, sql string, values ...interface{}) (err error) {
if txDB == nil {
return
}
_, err = txDB.Raw(sql, values).QueryRows(inPtr)
// _, err = db.Db.Raw(sql, values).QueryRows(inPtr)
return err
}
func GetEntity(db *DaoDB, item interface{}, cols ...string) (err error) { func GetEntity(db *DaoDB, item interface{}, cols ...string) (err error) {
if db == nil { if db == nil {
db = GetDB() db = GetDB()
@@ -225,8 +234,22 @@ func ExecuteSQL(db *DaoDB, sql string, params ...interface{}) (num int64, err er
// 此函数要求db在事务中否则可能导致取得到的是另一个连接的数据 // 此函数要求db在事务中否则可能导致取得到的是另一个连接的数据
func GetLastTotalRowCount(db *DaoDB) int { func GetLastTotalRowCount(db *DaoDB) int {
countInfo := &struct{ Ct int }{} countInfo := &struct{ Ct int }{}
// if err := txDB.Raw("SELECT FOUND_ROWS() ct", nil).QueryRow(countInfo); err == nil {
// return countInfo.Ct
// }
if err := GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil { if err := GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
return countInfo.Ct return countInfo.Ct
} }
return 0 return 0
} }
func GetLastTotalRowCount2(db *DaoDB, txDB orm.TxOrmer) int {
countInfo := &struct{ Ct int }{}
if err := txDB.Raw("SELECT FOUND_ROWS() ct", nil).QueryRow(countInfo); err == nil {
return countInfo.Ct
}
// if err := GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
// return countInfo.Ct
// }
return 0
}