This commit is contained in:
@@ -81,6 +81,30 @@ func (s *PollingLifecycleService) OnCardStatusChanged(ctx context.Context, cardI
|
||||
s.enqueueCard(ctx, card)
|
||||
}
|
||||
|
||||
// OnBatchCardsStatusChanged 批量卡状态变化:单次 Redis pipeline 清理 + 单次 DB 批量查询
|
||||
// 替代 N 次 OnCardStatusChanged 调用,避免批量分配/回收时打满 DB 连接池
|
||||
func (s *PollingLifecycleService) OnBatchCardsStatusChanged(ctx context.Context, cardIDs []uint) {
|
||||
if len(cardIDs) == 0 {
|
||||
return
|
||||
}
|
||||
// 单次 pipeline:批量从当前分片队列移除并清理缓存
|
||||
if err := s.queueMgr.RemoveBatchFromCurrentShardQueues(ctx, cardIDs); err != nil {
|
||||
s.logger.Warn("批量卡状态变化:从队列移除失败", zap.Int("count", len(cardIDs)), zap.Error(err))
|
||||
}
|
||||
// 单次 DB 查询:批量加载所有卡信息
|
||||
cards, err := s.iotCardStore.GetByIDs(ctx, cardIDs)
|
||||
if err != nil {
|
||||
s.logger.Error("批量卡状态变化:加载卡信息失败", zap.Int("count", len(cardIDs)), zap.Error(err))
|
||||
return
|
||||
}
|
||||
for _, card := range cards {
|
||||
if !s.shouldEnqueue(ctx, card) {
|
||||
continue
|
||||
}
|
||||
s.enqueueCard(ctx, card)
|
||||
}
|
||||
}
|
||||
|
||||
// OnCardDeleted 卡删除后移除所有队列并清理缓存
|
||||
func (s *PollingLifecycleService) OnCardDeleted(ctx context.Context, cardID uint) {
|
||||
if err := s.queueMgr.OnCardDeleted(ctx, cardID); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user