- try to fix SQL_CALC_FOUND_ROWS (use transaction)
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
type SkuNamesInfo struct {
|
||||
@@ -266,13 +265,10 @@ func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize
|
||||
}
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
skuNamesInfo = &SkuNamesInfo{}
|
||||
globals.SugarLogger.Debug(sqlData)
|
||||
globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||
dao.Begin(db)
|
||||
dao.Begin(db) // todo 这里用事务的原因是,SQL_CALC_FOUND_ROWS会出错
|
||||
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
|
||||
countInfo := &struct{ Ct int }{}
|
||||
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
|
||||
globals.SugarLogger.Debug(utils.Format4Output(countInfo, false))
|
||||
skuNamesInfo.TotalCount = countInfo.Ct
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
if skuName.SkusStr != "" {
|
||||
|
||||
@@ -183,12 +183,14 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
retVal = &StoresInfo{}
|
||||
db := dao.GetDB()
|
||||
dao.Begin(db)
|
||||
if err = dao.GetRows(db, &retVal.Stores, sql, sqlParams...); err == nil {
|
||||
countInfo := &struct{ Ct int }{}
|
||||
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
|
||||
retVal.TotalCount = countInfo.Ct
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
|
||||
@@ -155,6 +155,7 @@ func GetStoreSkus(storeID int, keyword string, params map[string]interface{}, of
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
skuNamesInfo = &StoreSkuNamesInfo{}
|
||||
// globals.SugarLogger.Debug(sqlData)
|
||||
dao.Begin(db)
|
||||
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
|
||||
countInfo := &struct{ Ct int }{}
|
||||
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
|
||||
@@ -168,6 +169,7 @@ func GetStoreSkus(storeID int, keyword string, params map[string]interface{}, of
|
||||
}
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
return skuNamesInfo, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user