2 Commits

Author SHA1 Message Date
1b47c9f027 refactor(video): 计数改由业务事务维护并删除热度第二条写路径
点赞与评论的计数只由业务事务写。ApplyLike、ApplyUnlike、CreateIdempotentWithPopularity 与 DeleteWithPopularity 各自在单事务内完成插行与计数。
热榜增量改为提交后的 best-effort 写。ApplyHotDelta 按行的 created_at 落分钟桶,写失败只记日志,DB 计数仍然正确。
删除 PopularityMQ 与 PopularityWorker。同一次互动因此只有一个写者,不再有两个门闩各自放行。
删除 hot:applied 占位键。判重改由 likes 的唯一索引与 uk_comments_author_key 负责。
DeleteWithPopularity 先读行再删行。评论删除因此回退热度,重复投递不再多减一次。
likes 与 comments 各加 (created_at, video_id) 覆盖索引,服务热榜窗口查询。
验证:go build -buildvcs=false ./... 通过。go test -buildvcs=false -count=1 ./... 全绿。
2026-11-01 15:15:15 +08:00
07f3166ab7 test(worker): 兜底写入与消费者收敛到一条评论
All checks were successful
CI/CD / Verify and Deploy (push) Successful in 4m42s
用例把两条路径接起来跑。评论事件发布失败,服务层直写数据库。
稍后同一个意图键的事件到达消费者。因此评论只留一行,popularity 恰为 1。

只跑兜底或只跑消费者都发现不了双写。所以它必须是端到端用例。

验证:go test -tags integration -p 1 -count=1 ./internal/worker/ 全绿
2026-10-30 15:35:52 +08:00