Эх сурвалжийг харах

Merge branch 'hotfix/v4.7.8.2' of ssh://192.168.3.207:10022/qmx/jy into hotfix/v4.7.8.2

cuiyalong 3 жил өмнө
parent
commit
75f648c0b6

+ 4 - 3
src/config.json

@@ -222,14 +222,15 @@
         }
     },
     "limitSearchText": {
-        "flag": false,
-        "count": 3,
+        "flag": true,
+        "count": 40,
         "timeout": 60,
         "totalPage": 10,
         "percentage":80,
         "userIds": [
         ],
-        "msg": "f 开关状态:%s //-2 从配置文件重置,-1 关闭,1 打开<br><br>c 并发数:%d //-2 不限制并发数,-1 无条件直接限制,>0 限制并发数<br><br>t 个人查询限制时间:%ds //-1 不限制<br><br>p 限制页数:%d"
+        "msg": "f 开关状态:%s //-2 从配置文件重置,-1 关闭,1 打开<br><br>c 并发数:%d //-2 不限制并发数,-1 无条件直接限制,>0 限制并发数<br><br>t 个人查询限制时间:%ds //-1 不限制<br><br>p 限制页数:%d",
+        "limitKey":"pc_limit_%s"
     },
     "share": {
         "forceShareEnabled": false,

+ 26 - 22
src/jfw/public/limitSearchText.go

@@ -14,13 +14,15 @@ import (
 var Lst *LimitSearchText
 
 type LimitSearchText struct {
-	TimeOut    int
-	Count      int
-	UserIds    []string
-	Flag       bool
-	TotalPage  int
-	Msg        string
-	Percentage int
+	TimeOut      int
+	Count        int
+	UserIds      []string
+	Flag         bool
+	TotalPage    int
+	Msg          string
+	Percentage   int
+	LimitKey     string
+	LimitKeyUser string
 }
 
 func IsSearchLimit(searchItems []string) bool {
@@ -36,13 +38,15 @@ func IsSearchLimit(searchItems []string) bool {
 func InitLimitSearchText(flag bool) {
 	limitSearchConfig, _ := config.Sysconfig["limitSearchText"].(map[string]interface{})
 	Lst = &LimitSearchText{
-		TimeOut:    util.IntAllDef(limitSearchConfig["timeout"], 60),
-		UserIds:    util.ObjArrToStringArr(limitSearchConfig["userIds"].([]interface{})),
-		Count:      util.IntAllDef(limitSearchConfig["count"], 3),
-		TotalPage:  util.IntAllDef(limitSearchConfig["totalPage"], 3),
-		Flag:       limitSearchConfig["flag"].(bool),
-		Msg:        limitSearchConfig["msg"].(string),
-		Percentage: util.IntAllDef(limitSearchConfig["percentage"], 80),
+		TimeOut:      util.IntAllDef(limitSearchConfig["timeout"], 60),
+		UserIds:      util.ObjArrToStringArr(limitSearchConfig["userIds"].([]interface{})),
+		Count:        util.IntAllDef(limitSearchConfig["count"], 3),
+		TotalPage:    util.IntAllDef(limitSearchConfig["totalPage"], 3),
+		Flag:         limitSearchConfig["flag"].(bool),
+		Msg:          limitSearchConfig["msg"].(string),
+		Percentage:   util.IntAllDef(limitSearchConfig["percentage"], 80),
+		LimitKey:     fmt.Sprintf(util.ObjToString(limitSearchConfig["limitKey"]), "jy_limitSearchText"),
+		LimitKeyUser: fmt.Sprintf(util.ObjToString(limitSearchConfig["limitKey"]), "%s"),
 	}
 	if !Lst.Flag {
 		return
@@ -54,11 +58,11 @@ func InitLimitSearchText(flag bool) {
 func (l *LimitSearchText) Init() {
 	l.Clear()
 	for i := 0; i < Lst.Count; i++ {
-		redis.RPUSH("other", "jy_limitSearchText", 1)
+		redis.RPUSH("other", l.LimitKey, 1)
 	}
 }
 func (l *LimitSearchText) Clear() {
-	redis.Del("other", "jy_limitSearchText")
+	redis.Del("other", l.LimitKey)
 }
 
 //限制正文查询
@@ -69,18 +73,18 @@ func (l *LimitSearchText) IsLimited(r *http.Request, w http.ResponseWriter, s *h
 	if !l.Flag {
 		return 1
 	}
-	var llen = int(redis.LLEN("other", "jy_limitSearchText"))
+	var llen = int(redis.LLEN("other", l.LimitKey))
 	if l.TimeOut > 0 {
 		limitFlag, isNew := l.getFlag(r, w, s)
 		if isNew {
 			if llen <= l.Count/2 {
-				timeLimit, _ := redis.Exists("other", "jy_limitSearchText_"+limitFlag)
+				timeLimit, _ := redis.Exists("other", fmt.Sprintf(l.LimitKeyUser, limitFlag))
 				if timeLimit {
 					return -1
 				}
 			}
 		}
-		redis.Put("other", "jy_limitSearchText_"+limitFlag, 1, l.TimeOut)
+		redis.Put("other", fmt.Sprintf(l.LimitKeyUser, limitFlag), 1, l.TimeOut)
 	}
 	if l.Count == -2 {
 		return 1
@@ -94,7 +98,7 @@ func (l *LimitSearchText) IsLimited(r *http.Request, w http.ResponseWriter, s *h
 		}
 	}
 	//
-	pollLimit := redis.LPOP("other", "jy_limitSearchText")
+	pollLimit := redis.LPOP("other", l.LimitKey)
 	if util.IntAll(pollLimit) <= 0 {
 		return -2
 	}
@@ -104,8 +108,8 @@ func (l *LimitSearchText) Limit() {
 	if !l.Flag {
 		return
 	}
-	if int(redis.LLEN("other", "jy_limitSearchText")) < l.Count {
-		redis.RPUSH("other", "jy_limitSearchText", 1)
+	if int(redis.LLEN("other", l.LimitKey)) < l.Count {
+		redis.RPUSH("other", l.LimitKey, 1)
 	}
 }
 func (l *LimitSearchText) getFlag(r *http.Request, w http.ResponseWriter, s *httpsession.Session) (string, bool) {