From 07eea46970759aba106f3db3f4bc24c518ab41de Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 20 二月 2024 14:39:04 +0800 Subject: [PATCH] 库中新增更新单条缓存 --- cache/compare.go | 62 +++++++------------------------ 1 files changed, 14 insertions(+), 48 deletions(-) diff --git a/cache/compare.go b/cache/compare.go index ffaa428..d2e5b23 100644 --- a/cache/compare.go +++ b/cache/compare.go @@ -266,56 +266,22 @@ } } -// UpdateDbPersonsCache 鏇存柊缂撳瓨涓殑鍏ㄩ儴浜哄憳淇℃伅 -func UpdateDbPersonsCache() { +// UpdateDbPersonsCacheById 鏇存柊缂撳瓨涓殑鍏ㄩ儴浜哄憳淇℃伅 +func UpdateDbPersonsCacheById(id string) { 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 + info, err := dbpApi.GetPersonsCompareCacheById(id) + if err != nil { + logger.Debug(err) + return + } + if info.Tableid != "" { + Cmap.Lock() + defer Cmap.Unlock() + if _, ok := Cmap.Cam[info.Tableid]; !ok { + Cmap.Cam[info.Tableid] = shardmap.New(uint8(*threadnum)) } - 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)) + Cmap.Cam[info.Tableid].Set(info.Id, info) + Cmap.Cam[info.Tableid].Settime() } } -- Gitblit v1.8.0