소스 검색

refactor(internal): 优化 IP计数和筛选逻辑

-将多个 for 循环合并到一个函数中,提高代码可读性
- 修改 IP 筛选条件,从总引用数小于 2 变为等于 1
- 修复 webForwardingRepository 中的错误处理
fusu 3 주 전
부모
커밋
c89f9adbb6
1개의 변경된 파일3개의 추가작업 그리고 3개의 파일을 삭제
  1. 3 3
      internal/service/wafformatter.go

+ 3 - 3
internal/service/wafformatter.go

@@ -452,7 +452,7 @@ func (s *wafFormatterService) WashDelIps(ctx context.Context, ips []string) ([]s
 
 	// 2. 汇总所有计数结果
 	totalCountMap := make(map[string]int)
-	// 将多个 for 循环合并到一个函数中,可以显得更整洁(可选)
+	// 将多个 for 循环合并到一个函数中
 	accumulateCounts := func(counts []v1.IpCountResult) {
 		for _, result := range counts {
 			totalCountMap[result.Ip] += result.Count
@@ -462,10 +462,10 @@ func (s *wafFormatterService) WashDelIps(ctx context.Context, ips []string) ([]s
 	accumulateCounts(tcpIpCounts)
 	accumulateCounts(webIpCounts)
 
-	// 3. 筛选出总引用数小于 2 的 IP
+	// 3. 筛选出总引用数等于 1 的 IP
 	var ipsToDelist []string
 	for _, ip := range ips {
-		if totalCountMap[ip] < 2 {
+		if totalCountMap[ip] == 1 {
 			ipsToDelist = append(ipsToDelist, ip)
 		}
 	}