From 7779e07bd84d081a8f14ef976397dc4c19b0e994 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 20 二月 2024 14:02:33 +0800 Subject: [PATCH] 库中新增更新缓存 --- cache/compare.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/cache/compare.go b/cache/compare.go index a76e0c8..ffaa428 100644 --- a/cache/compare.go +++ b/cache/compare.go @@ -266,6 +266,59 @@ } } +// UpdateDbPersonsCache 鏇存柊缂撳瓨涓殑鍏ㄩ儴浜哄憳淇℃伅 +func UpdateDbPersonsCache() { + var dbpApi DbPersons + total, e := dbpApi.GetPersonTotal("") + logger.Debugf("鎵�鏈夊簳搴撳叡鏈�%d鏉¤褰�", total) + if e == nil && total > 0 { + queryEachNum := *querynum + qn := int(total) / *threadnum + if *querynum < qn { + queryEachNum = qn + } + queryT := int(total) / queryEachNum + if int(total)%queryEachNum > 0 { + queryT++ + } + temptime := time.Now() + var wg sync.WaitGroup + + for i := 0; i < queryT; i++ { + j := i * queryEachNum + wg.Add(1) + go func(qs int) { + defer wg.Done() + dbpersons, err := dbpApi.GetPersonsCompareCacheBase(j, queryEachNum) + if err != nil { + logger.Debug(err) + return + } + logger.Debugf("鑾峰彇%d鏉′汉鍛樹俊鎭�", len(dbpersons)) + Cmap.Lock() + tableId := "" + for _, value := range dbpersons { + tableId = value.Tableid + if _, ok := Cmap.Cam[value.Tableid]; !ok { + Cmap.Cam[value.Tableid] = shardmap.New(uint8(*threadnum)) + } + + Cmap.Cam[value.Tableid].Set(value.Id, value) + } + + if len(dbpersons) != 0 { + Cmap.Cam[tableId].Settime() + } + + Cmap.Unlock() + + }(j) + } + wg.Wait() + logger.Debug("搴曞簱浜哄憳缂撳瓨瀹屾垚鐢ㄦ椂:", time.Since(temptime)) + } +} + func RealTimeAddPersonInfoToCache(tableId string, id string, faceFeature string, enable int32, carNo string) { Cmap.Lock() defer Cmap.Unlock() -- Gitblit v1.8.0