Browse Source

Merge branch 'master' into feature/v4.9.64

yuelujie 9 tháng trước cách đây
mục cha
commit
3cef5eff6b
2 tập tin đã thay đổi với 50 bổ sung14 xóa
  1. 49 13
      src/jfw/front/tags.go
  2. 1 1
      src/web/templates/pc/brand/index.html

+ 49 - 13
src/jfw/front/tags.go

@@ -3,6 +3,7 @@ package front
 import (
 	"context"
 	"fmt"
+	"github.com/gogf/gf/v2/container/gvar"
 	"jy/src/jfw/config"
 	"jy/src/jfw/jyutil"
 	"jy/src/jfw/paging"
@@ -45,7 +46,11 @@ type reqLimit struct {
 	waitPool chan struct{}
 }
 
-var reqLimitInit *reqLimit
+var (
+	reqLimitInit     *reqLimit
+	BlogQueryLock    = new(sync.RWMutex)
+	HotWordQueryLock = new(sync.RWMutex)
+)
 
 func init() {
 	xweb.AddAction(&Tags{})
@@ -578,13 +583,41 @@ func (this *Tags) GetStype(href string) (list []map[string]interface{}) {
 	return list
 }
 
+// GetL2CacheData 二级缓存
+// 注意 lock定义为全局锁
+func GetL2CacheData(dbName string, lock *sync.RWMutex, key string, f func() interface{}, cacheSec int) *gvar.Var {
+	var (
+		data    = gvar.New(redis.Get(dbName, key))
+		newData *gvar.Var
+	)
+	if data.IsEmpty() {
+		data = gvar.New(redis.Get(dbName, fmt.Sprintf("%s_L2Cache", key)))
+		go func() {
+			if lock.TryLock() {
+				defer lock.Unlock()
+				if n := f(); n != nil {
+					newData = gvar.New(n)
+					go func() {
+						redis.Put(dbName, key, newData, cacheSec)
+						redis.Put(dbName, fmt.Sprintf("%s_L2Cache", key), newData, -1)
+					}()
+				}
+			}
+		}()
+		if data.IsEmpty() {
+			time.Sleep(100 * time.Millisecond)
+			if !newData.IsEmpty() {
+				data = newData
+			}
+		}
+	}
+	return data
+}
+
 // 剑鱼博客
-func (this *Tags) GetConsult() (list []map[string]interface{}) {
+func (this *Tags) GetConsult() []map[string]interface{} {
 	rediskey := fmt.Sprintf("pcseo_jybk")
-	if l, ok := redis.Get("seoCache", rediskey).([]interface{}); ok && l != nil && len(l) > 0 {
-		list = qu.ObjArrToMapArr(l)
-	} else {
-
+	res := GetL2CacheData("seoCache", BlogQueryLock, rediskey, func() interface{} {
 		rs, _, _ := jyutil.JyCmsSearch(map[string]string{
 			"perPage": "10",
 		}, "/jyblog/index_%s.html")
@@ -595,11 +628,14 @@ func (this *Tags) GetConsult() (list []map[string]interface{}) {
 				delete(v, "s_source")
 				v["url"] = fmt.Sprintf("/jyblog/%s.html", qu.ObjToString(v["_id"]))
 			}
-			list = *rs
-			redis.Put("seoCache", rediskey, list, cacheTime)
 		}
+		return rs
+	}, cacheTime)
+	log.Println(res.Maps())
+	if !res.IsEmpty() {
+		return res.Maps()
 	}
-	return list
+	return nil
 }
 
 func (this *Tags) GetLetterMap(pageSize, pageNum int64, letter string) ([]map[string]interface{}, int64) {
@@ -627,9 +663,7 @@ func (this *Tags) GetLetterMap(pageSize, pageNum int64, letter string) ([]map[st
 
 func (this *Tags) GetHotLabel(length int64) []map[string]interface{} {
 	rediskey := fmt.Sprintf("pcseo_getHotLabel_%v", length)
-	if l, ok := redis.Get("seoCache", rediskey).([]interface{}); ok && l != nil && len(l) > 0 {
-		return qu.ObjArrToMapArr(l)
-	} else {
+	res := GetL2CacheData("seoCache", HotWordQueryLock, rediskey, func() interface{} {
 		m := []map[string]interface{}{}
 		sql := `select id,name,letter from seo_words.seo_resource where state1=2`
 		cql := `select count(1) from seo_words.seo_resource where state1=2`
@@ -650,8 +684,10 @@ func (this *Tags) GetHotLabel(length int64) []map[string]interface{} {
 				})
 			}
 		}
-		redis.Put("seoCache", rediskey, m, cacheTime)
 		return m
+	}, cacheTime)
+	if !res.IsEmpty() {
+		return res.Maps()
 	}
 	return nil
 }

+ 1 - 1
src/web/templates/pc/brand/index.html

@@ -111,7 +111,7 @@
         <div class="item-content">以剑鱼标讯收录的海量招投标信息及企业公示数据为基础,实现省、市、县三级数据联动,通过对源数据进行清洗、整理、分析,提供相应的行业解决方案。</div>
         <div class="item-link">了解详情</div>
       </div>
-      <div class="plan-item plan-item-2" onclick="window.open('http://clpages.cn/yxtgwyxy?from_wecom=1')">
+      <div class="plan-item plan-item-2" onclick="window.open('https://www.jianyu360.cn/hj/pc/yxtsjgwyxy.html?from_wecom=1')">
         <div class="item-icon"></div>
         <div class="item-header">医疗器械</div>
         <div class="item-content">为企业提供医疗市场情报、竞争对手情报、客户情报、合作伙伴情报、商机管理等服务,帮助企业全面透视市场情况,解决医疗器械市场数据监测难题,辅助市场决策,做好渠道建设和维护,提升企业竞争力。</div>