refactor(p0-5): 收敛热度相关注释

背景叙述与历史取舍已写进 `docs/design/hot-ranking.md`,从源码删除。
只保留不变式与安全约束:`clientFoundRows` 禁令、唯一索引判重、
成员补零的排序约定、快照用 `RENAMENX` 只建一次、`EXPIRE` 失败即删键。

`video_service.go` 的 `NewVideoService` 注释原本复述已删方法的来历,一并收敛。
`zset.go` 的 `ZUnionStore` 与 `RenameNX` 注释各压到四行以内。

验证:go build ./... 通过。
验证:go vet ./... 通过。
验证:go test -count=1 ./... 全绿(本机无 cgo,未跑 -race)。
验证:go test -tags integration -p 1 -count=1 ./internal/feed/ ./internal/video/ ./internal/worker/ 全绿。
This commit is contained in:
2026-11-01 16:47:31 +08:00
parent 006ec5f196
commit d782ccbb53
16 changed files with 74 additions and 132 deletions

View File

@@ -23,9 +23,10 @@ func (r *CommentRepository) CreateComment(ctx context.Context, comment *Comment)
return r.db.WithContext(ctx).Create(comment).Error
}
// CreateIdempotentWithPopularity 由 uk_comments_author_key 判重。
// 热度增量与插入必须同事务,只在 created=true 时执行。
// 注意:DSN 不能开 clientFoundRows,否则 RowsAffected 恒为 1,判重失效。
// CreateIdempotentWithPopularity 由 uk_comments_author_key 判重,
// 热度增量与插入同事务,只在 created=true 时执行。
//
// DSN 不能开 clientFoundRows,否则 RowsAffected 恒为 1,判重失效。
func (r *CommentRepository) CreateIdempotentWithPopularity(ctx context.Context, c *Comment, delta int64) (bool, error) {
var created bool
err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
@@ -52,11 +53,8 @@ func (r *CommentRepository) CreateIdempotentWithPopularity(ctx context.Context,
// DeleteWithPopularity 删除评论,并在同一事务里把所属视频的 popularity 减 1。
//
// 返回被删的那一行:调用方要它的 created_at 把热榜分数减回评论发布那一刻的
// 分钟桶,还要它的 video_id 定位视频。这两个值都从库里取,比事件里的快照
// 更可信——事件到达时行可能已经被别的路径删掉了。
//
// deleted=false 表示没有这一行(重复投递的删除),此时不能再减热度。
// 返回被删的行:调用方要它的 created_at 落桶、要 video_id 定位视频,
// 这两个值从库里取比从事件里取可信。
func (r *CommentRepository) DeleteWithPopularity(ctx context.Context, id uint) (*Comment, bool, error) {
if id == 0 {
return nil, false, nil