liujiandao
2024-02-20 7779e07bd84d081a8f14ef976397dc4c19b0e994
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()