| | |
| | | } |
| | | } |
| | | |
| | | // 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() |
| | | } |
| | | } |
| | | |