Quellcode durchsuchen

feat:搜索限制

wangshan vor 3 Jahren
Ursprung
Commit
3c52b077b4

+ 2 - 1
jyBXCore/rpc/etc/bxcore.yaml

@@ -14,11 +14,12 @@ LabelUrl:
 PCSTime: 24
 LimitSearchText:
   Flag: true
-  Count: 3
+  Count: 40
   TimeOut: 60
   Percentage: 80
   UserIds:
     - 60f4f01156bf6da1bcbbcff6
   Msg: f 开关状态:%s //-2 从配置文件重置,-1 关闭,1 打开<br><br>c 并发数:%d //-2 不限制并发数,-1 无条件直接限制,>0 限制并发数<br><br>t 个人查询限制时间:%ds //-1 不限制<br><br>
+  LimitKey: mobile_limit_%s
 SearchTypeSwitch: true
 FileSignBool: true

+ 7 - 0
jyBXCore/rpc/init/init.go

@@ -2,6 +2,7 @@ package init
 
 import (
 	"flag"
+	"fmt"
 	_ "github.com/go-sql-driver/mysql"
 	"github.com/zeromicro/go-zero/core/conf"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -21,6 +22,10 @@ var DB config.Db
 var logFile = flag.String("lf", "etc/logs.yaml", "the logs file")
 var logc entity.Logc
 
+//全文或附件搜索限制
+var SearchLimitKey = "jy_limitSearchText_new"
+var SearchLimitFlag = "jy_limitSearchText_%s"
+
 func init() {
 	//基本配置
 	conf.MustLoad(*configFile, &C)
@@ -49,4 +54,6 @@ func init() {
 	}
 	//初始化标签
 	LabelInit()
+	//
+	SearchLimitKey = fmt.Sprintf(C.LimitSearchText.LimitKey, "jy_limitSearchText")
 }

+ 1 - 0
jyBXCore/rpc/internal/config/config.go

@@ -22,6 +22,7 @@ type Config struct {
 		Percentage int
 		UserIds    []string
 		Msg        string
+		LimitKey   string
 	}
 	SearchTypeSwitch bool
 	FileSignBool     bool

+ 8 - 11
jyBXCore/rpc/util/limitSearchText.go

@@ -7,9 +7,6 @@ import (
 	IC "jyBXCore/rpc/init"
 )
 
-var SearchLimitKey = "jy_limitSearchText_new"
-var SearchLimitFlag = "jy_limitSearchText_%s"
-
 //标讯搜索:全文搜索和附件搜索限制
 func IsSearchLimit(searchItems []string) bool {
 	for _, searchItem := range searchItems {
@@ -25,14 +22,14 @@ func LimitSearchInit() {
 	if IC.C.LimitSearchText.Flag {
 		LimitSearchClear()
 		for i := 0; i < IC.C.LimitSearchText.Count; i++ {
-			redis.RPUSH("other", SearchLimitKey, 1)
+			redis.RPUSH("other", IC.SearchLimitKey, 1)
 		}
 	}
 }
 
 //
 func LimitSearchClear() {
-	redis.Del("other", SearchLimitKey)
+	redis.Del("other", IC.SearchLimitKey)
 }
 
 //限制正文、附件查询
@@ -43,15 +40,15 @@ func IsLimited(userId string, isPayedUser bool) int64 {
 	if !IC.C.LimitSearchText.Flag {
 		return 1
 	}
-	var llen = int(redis.LLEN("other", SearchLimitKey))
+	var llen = int(redis.LLEN("other", IC.SearchLimitKey))
 	if IC.C.LimitSearchText.TimeOut > 0 {
 		if llen <= IC.C.LimitSearchText.Count/2 {
-			timeLimit, _ := redis.Exists("other", fmt.Sprintf(SearchLimitFlag, userId))
+			timeLimit, _ := redis.Exists("other", fmt.Sprintf(IC.C.LimitSearchText.LimitKey, userId))
 			if timeLimit {
 				return -1
 			}
 		}
-		redis.Put("other", fmt.Sprintf(SearchLimitFlag, userId), 1, IC.C.LimitSearchText.TimeOut)
+		redis.Put("other", fmt.Sprintf(IC.C.LimitSearchText.LimitKey, userId), 1, IC.C.LimitSearchText.TimeOut)
 	}
 
 	if IC.C.LimitSearchText.Count == -2 { //不限制
@@ -66,7 +63,7 @@ func IsLimited(userId string, isPayedUser bool) int64 {
 		}
 	}
 	//
-	pollLimit := redis.LPOP("other", SearchLimitKey)
+	pollLimit := redis.LPOP("other", IC.SearchLimitKey)
 	if MC.IntAll(pollLimit) <= 0 {
 		return -2
 	}
@@ -78,8 +75,8 @@ func Limit() {
 	if !IC.C.LimitSearchText.Flag {
 		return
 	}
-	if int(redis.LLEN("other", SearchLimitKey)) < IC.C.LimitSearchText.Count {
-		redis.RPUSH("other", SearchLimitKey, 1)
+	if int(redis.LLEN("other", IC.SearchLimitKey)) < IC.C.LimitSearchText.Count {
+		redis.RPUSH("other", IC.SearchLimitKey, 1)
 	}
 }