Commit e3bcc1db by mushishixian

修改匹配请求量

parent a7126d63
Showing with 18 additions and 8 deletions
......@@ -30,7 +30,7 @@ func MatchGoods(message model.BomMessage) (err error) {
if configs.ApiSetting.Mode == "debug" {
perGoDealNumber = 200
} else {
perGoDealNumber = 40
perGoDealNumber = 100
}
//开启协程处理搜索
var wg sync.WaitGroup
......@@ -80,14 +80,23 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
bomItems = common.TrimBomItemSpace(bomItems)
//获取转换后的标准参数,或者是识别出参数列是否有型号
bomItems = GetStandardAttrs(bomItems)
//线上es性能垃圾,批量请求条数或者并发数过高,就会拒绝请求,只能用循环,控制每次批量请求的条数,所以要循环再处理
perNumber := 5
var needDealBomItems []model.BomItem
for i := 0; i < len(bomItems); i = i + perNumber {
if i+perNumber > len(bomItems) {
needDealBomItems = bomItems[i:]
} else {
needDealBomItems = bomItems[i : i+perNumber]
}
//第一次先去精确匹配
goodsMapList, err := getUpdateGoodsData(bomId, bomItems, deliveryType, sort, client, true)
goodsMapList, err := getUpdateGoodsData(bomId, needDealBomItems, deliveryType, sort, client, true)
if err != nil {
return
return err
}
//要删除已经精确匹配过的bomItem,得到需要去模糊匹配的商品
var fuzzyBomItems []model.BomItem
for _, bomItem := range bomItems {
for _, bomItem := range needDealBomItems {
//不在精确匹配结果里面的,同时商品名称不能为空的
if !checkInGoodsMap(bomItem, goodsMapList) && bomItem.GoodsName != "" {
fuzzyBomItems = append(fuzzyBomItems, bomItem)
......@@ -96,12 +105,12 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
//第二次去模糊匹配
fuzzyGoodsMapList, err := getUpdateGoodsData(bomId, fuzzyBomItems, deliveryType, sort, client, false)
if err != nil {
return
return err
}
//再删除模糊匹配到的数据,就得到完全没有匹配的数据了
var notMatchBomItems []model.BomItem
var needMatchGoodsMapList = append(goodsMapList, fuzzyGoodsMapList...)
for _, bomItem := range bomItems {
for _, bomItem := range needDealBomItems {
if !checkInGoodsMap(bomItem, needMatchGoodsMapList) {
notMatchBomItems = append(notMatchBomItems, bomItem)
}
......@@ -109,12 +118,13 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
//先去处理没有匹配到的数据
err = UpdateNoMatchBomItem(notMatchBomItems, true)
if err != nil {
return
return err
}
//然后去处理匹配到的数据
err = UpdateGoodsData(needMatchGoodsMapList)
if err != nil {
return
return err
}
}
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment