From a8ae37c641b9ea518e379ac54b7a66d78808251b Mon Sep 17 00:00:00 2001 From: gazebo Date: Sat, 15 Sep 2018 23:04:46 +0800 Subject: [PATCH] - try to fix SQL_CALC_FOUND_ROWS (use transaction) --- business/jxstore/cms/sku.go | 6 +----- business/jxstore/cms/store.go | 2 ++ business/jxstore/cms/store_sku.go | 2 ++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/business/jxstore/cms/sku.go b/business/jxstore/cms/sku.go index 9edd33f45..9d0a0073c 100644 --- a/business/jxstore/cms/sku.go +++ b/business/jxstore/cms/sku.go @@ -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 != "" { diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 51fa5c12e..f3eb5d89c 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -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 } diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 21acaa34a..334b9bfde 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -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 }