瀏覽代碼

Merge branch 'master' into feature/v4.9.19

lianbingjie 1 年之前
父節點
當前提交
a623dde1de
共有 2 個文件被更改,包括 43 次插入28 次删除
  1. 1 1
      src/jfw/front/pcIndex.go
  2. 42 27
      src/jfw/front/tags.go

+ 1 - 1
src/jfw/front/pcIndex.go

@@ -611,7 +611,7 @@ func (f *PcIndex) SearchResult(at, name string) error {
 		//
 		list := redis.Get("other", "classify_"+name)
 		if list == nil || len(list.([]interface{})) == 0 {
-			rl.Unlock()
+			rl.Lock()
 			sl = true
 			list = redis.Get("other", "classify_sl_"+name)
 			rl.Unlock()

+ 42 - 27
src/jfw/front/tags.go

@@ -464,6 +464,8 @@ func (this *Tags) GetNewBidInfo() (list []map[string]interface{}) {
 		redisKey   = fmt.Sprintf("pcindex_newArticle")
 		redisKeySL = fmt.Sprintf("pcindex_newArticle_second_level") //二级缓存
 		redisLock  = &sync.Mutex{}
+		ri         int
+		rn         = 3
 	)
 	var newBidInfos = func() (list []map[string]interface{}) {
 		// p397 未登录详情页最新招投标信息去掉拟建
@@ -475,10 +477,10 @@ func (this *Tags) GetNewBidInfo() (list []map[string]interface{}) {
 		)
 		_, _, lists := bidsearch.GetPcBidSearchData("", "", "", publishTime, "招标预告,招标公告,招标结果,招标信用信息", "", "", "", "", "", "", "", "", 1, false, nil, bidSearch_field_1, "", false, false, "", 50, "")
 		if lists != nil && len(*lists) > 0 {
-			for k, v := range *lists {
-				if k >= 10 {
-					break
-				}
+			if len(*lists) > 10 {
+				*lists = (*lists)[:10]
+			}
+			for _, v := range *lists {
 				v["_id"] = encrypt.CommonEncodeArticle("content", v["_id"].(string))
 				delete(v, "toptype")
 				delete(v, "s_subscopeclass")
@@ -496,29 +498,34 @@ func (this *Tags) GetNewBidInfo() (list []map[string]interface{}) {
 		return
 	}
 	var bidInfosByCache = func(rk string) (list []map[string]interface{}) {
-		redisLock.Lock()
-		defer redisLock.Unlock()
 		if l, ok := redis.Get("seoCache", rk).([]interface{}); ok && l != nil && len(l) > 0 {
 			list = qu.ObjArrToMapArr(l)
 		}
 		return
 	}
 	var bidInfosToCache = func(list []map[string]interface{}) {
-		redisLock.Lock()
-		defer redisLock.Unlock()
 		redis.Put("seoCache", redisKey, list, cacheTime)
-		redis.Put("seoCache", redisKeySL, list, -1)
-
+		ok := redis.Put("seoCache", redisKeySL, list, -1)
+		log.Println(redisKeySL, "--00--", ok)
 	}
-
 	list = bidInfosByCache(redisKey)
 	if len(list) == 0 {
 		list = bidInfosByCache(redisKeySL)
-		if len(list) == 0 {
-			list = newBidInfos()
-		}
-		if len(list) > 0 {
-			bidInfosToCache(list)
+		for {
+			if redisLock.TryLock() {
+				if len(list) == 0 {
+					list = newBidInfos()
+				}
+				if len(list) > 0 {
+					bidInfosToCache(list)
+				}
+				redisLock.Unlock()
+			}
+			ri++
+			if len(list) > 0 || ri >= rn {
+				break
+			}
+			time.Sleep(100 * time.Millisecond)
 		}
 	}
 	//rediskey := fmt.Sprintf("pcindex_newArticle")
@@ -732,6 +739,8 @@ func (this *Tags) GetBidding(industry, area, city, stype, keyword string, reques
 		data            []map[string]interface{}
 		count           int64
 		b               bool
+		ri              int
+		rn              = 3
 	)
 	var biddingData = func() ([]map[string]interface{}, int64, bool) {
 		if area != "" || stype != "" || industry != "" || city != "" || keyword != "" {
@@ -796,8 +805,6 @@ func (this *Tags) GetBidding(industry, area, city, stype, keyword string, reques
 		return nil, 0, false
 	}
 	var biddingByCache = func(rk, rc string) ([]map[string]interface{}, int64, bool) {
-		redisLock.Unlock()
-		defer redisLock.Unlock()
 		if l, ok := redis.Get("seoCache", rk).([]interface{}); ok && l != nil {
 			count := redis.GetInt("seoCache", rc)
 			return qu.ObjArrToMapArr(l), int64(count), false
@@ -805,8 +812,6 @@ func (this *Tags) GetBidding(industry, area, city, stype, keyword string, reques
 		return nil, 0, false
 	}
 	var biddingToCache = func(datas []map[string]interface{}, count int64) {
-		redisLock.Lock()
-		defer redisLock.Unlock()
 		redis.Put("seoCache", rediskey, datas, cacheTime)      //生产环境配置4G单独redis,超出4G自动清除
 		redis.Put("seoCache", rediskeyCount, count, cacheTime) //生产环境配置4G单独redis,超出4G自动清除
 		redis.Put("seoCache", redisKeySL, datas, -1)           //生产环境配置4G单独redis,超出4G自动清除
@@ -817,13 +822,23 @@ func (this *Tags) GetBidding(industry, area, city, stype, keyword string, reques
 	data, count, b = biddingByCache(rediskey, rediskeyCount)
 	if data == nil || len(data) == 0 || count == 0 {
 		data, count, b = biddingByCache(redisKeySL, redisKeyCountSL)
-		if data == nil || len(data) == 0 || count == 0 {
-			//获取数据库数据
-			data, count, b = biddingData()
-		}
-		//更新缓存
-		if data != nil && len(data) > 0 && count > 0 {
-			biddingToCache(data, count)
+		for {
+			if redisLock.TryLock() {
+				if data == nil || len(data) == 0 || count == 0 {
+					//获取数据库数据
+					data, count, b = biddingData()
+				}
+				//更新缓存
+				if data != nil && len(data) > 0 && count > 0 {
+					biddingToCache(data, count)
+				}
+				redisLock.Unlock()
+			}
+			ri++
+			if (data != nil && len(data) > 0 && count > 0) || ri >= rn {
+				break
+			}
+			time.Sleep(100 * time.Millisecond)
 		}
 	}
 	return data, count, b