fix: 修复轮询缓存竞态导致流量增量重复计全量的问题
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
getCardWithCache 在缓存 miss 时将 writeCardToCache 由异步协程改为同步调用。 原实现中协程可能在 updateCardCache 之后才被调度执行,将 last_gateway_reading_mb 覆盖回 DB 旧值(0),导致下次轮询 increment = gatewayFlowMB - 0 = 全量,触发套餐流量重复扣减。 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -25,7 +25,10 @@ func (b *PollingBase) getCardWithCache(ctx context.Context, cardID uint) (*model
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go writeCardToCache(b, key, card)
|
||||
// 同步写缓存,避免与后续 updateCardCache 产生竞态:
|
||||
// 若异步协程在 updateCardCache 之后才执行,会将 last_gateway_reading_mb
|
||||
// 覆盖回 DB 旧值(0),导致下次轮询增量重复计全量。
|
||||
writeCardToCache(b, key, card)
|
||||
return card, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user