From 366e2ff546092d9be26411fb698b3ddd8e834a11 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期一, 09 十二月 2024 15:38:02 +0800
Subject: [PATCH] 更新实名比对

---
 cache/shardmap/shardmap.go |   75 +++++++++++--------------------------
 1 files changed, 23 insertions(+), 52 deletions(-)

diff --git a/cache/shardmap/shardmap.go b/cache/shardmap/shardmap.go
index e53aa38..9d434d9 100644
--- a/cache/shardmap/shardmap.go
+++ b/cache/shardmap/shardmap.go
@@ -4,6 +4,7 @@
 
 import (
 	"basic.com/pubsub/protomsg.git"
+	"sdkCompare/db"
 	"sync"
 	//"encoding/json"
 	//"fmt"
@@ -28,7 +29,7 @@
 
 var Count = make(chan int)
 
-type wfOp func(a []byte, b string) float32
+type wfOp func(a, b []float32) float32
 
 /**
 * @param uint8, shardCnt must be pow of two
@@ -89,74 +90,44 @@
 	value interface{}
 }
 
-func (s *ShardMap) Walk(wf wfOp, sourceFea []byte, baseScore float32, isWebComp bool, target string) (targets []*protomsg.SdkCompareEach) {
+func (s *ShardMap) Walk(wf wfOp, sourceFea []float32, baseScore float32) (targets []*protomsg.SdkCompareEach) {
 	var wg sync.WaitGroup
 	var lock sync.Mutex
-	for _, si := range s.shards {
-		var tempsi shardItem = *si
 
+	for _, si := range s.shards {
+		var tempsi *shardItem = si // 淇濇寔瀵瑰師濮� shardItem 鐨勬寚閽堝紩鐢�
+
+		// 璺宠繃绌哄垎鐗�
 		if len(tempsi.data) == 0 {
 			continue
 		}
 
 		wg.Add(1)
-
-		go func(st *shardItem, fw wfOp, sf []byte, baseSec float32, isWeb bool) {
+		go func(st *shardItem, fn wfOp, srcFeat []float32, baseSec float32) {
 			defer wg.Done()
+			st.RLock()         // 閿佸畾璇诲彇
+			defer st.RUnlock() // 纭繚璇诲彇瀹屾瘯鍚庤В閿�
+
 			for _, feature := range st.data {
-				if eif, ok := feature.(*protomsg.Esinfo); ok {
-					if !isWeb { //涓嶄細姣斿鎶撴媿搴�,鍙瘮瀵规湁鏁堢殑浜�
-						if eif.Enable == 1 {
-							score := float32(0)
-							if target == "car" {
-								if eif.CarNo != "" {
-									score = strComp(sf, eif.CarNo)
-								} else {
-									continue
-								}
-							} else {
-								score = fw(sf, eif.FaceFeature)
-							}
-							if score > 0 && score >= baseScore {
-								lock.Lock()
-								targets = append(targets, &protomsg.SdkCompareEach{
-									Id:           eif.Id,
-									CompareScore: score,
-									Tableid:      eif.Tableid,
-								})
-								lock.Unlock()
-							}
-						}
-					} else { //鏉ユ簮鏄痺eb锛屼細姣斿鎶撴媿搴擄紝涓嶇鏄惁鏈夋晥閮介渶瑕佹瘮瀵�
-						score := float32(0)
-						if target == "car" {
-							if eif.CarNo != "" {
-								score = strComp(sf, eif.CarNo)
-							} else {
-								continue
-							}
-						} else {
-							score = fw(sf, eif.FaceFeature)
-						}
-						if score > 0 && score >= baseScore {
-							lock.Lock()
-							targets = append(targets, &protomsg.SdkCompareEach{
-								Id:           eif.Id,
-								CompareScore: score,
-								Tableid:      eif.Tableid,
-							})
-							lock.Unlock()
-						}
+				// 璇诲彇鎿嶄綔鍦ㄩ攣鍐呰繘琛岋紝闃叉骞跺彂鍐茬獊
+				if item, ok := feature.(*db.FeatureCacheBase); ok {
+					score := fn(srcFeat, item.FaceFeature)
+					if score > 0 && score >= baseScore {
+						lock.Lock() // 淇濇姢鐩爣鍒囩墖鐨勫啓鍏�
+						targets = append(targets, &protomsg.SdkCompareEach{
+							Id:           item.Id,
+							CompareScore: score,
+							Tableid:      item.TableId,
+						})
+						lock.Unlock()
 					}
 				}
 			}
-
-		}(&tempsi, wf, sourceFea, baseScore, isWebComp)
+		}(tempsi, wf, sourceFea, baseScore)
 	}
 
 	wg.Wait()
 	return targets
-
 }
 
 // print all

--
Gitblit v1.8.0