style(backend): 清理幂等写入路径的注释
注释只保留一行级约束。 长段理由移入设计文档。 验证:go test -count=1 ./... 全绿。
This commit is contained in:
@@ -4,12 +4,7 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// Mention 是一条"提及通知"的写入意图。
|
||||
//
|
||||
// DedupeKey 由 NotificationDedupeKey(notifType, intentKey, recipientID) 生成,
|
||||
// 落到 notifications 表的唯一索引 uk_notifications_dedupe 上。它让"同一次
|
||||
// 评论意图产生的提及通知"无论被写几次都只有一行——与评论本身用的是同一个
|
||||
// 意图键,所以两侧的判重是同一个语义,而不是两套各自为政的计数器。
|
||||
// Mention 是一条待写入的提及通知。
|
||||
type Mention struct {
|
||||
RecipientID uint
|
||||
SenderID uint
|
||||
@@ -18,16 +13,9 @@ type Mention struct {
|
||||
DedupeKey string
|
||||
}
|
||||
|
||||
// CommentStore 是 CommentService 与 CommentWorker 依赖的窄接口。
|
||||
//
|
||||
// 抽接口不是为了"面向接口编程",而是为了给"判重与写入必须发生在同一条 SQL
|
||||
// 的同一个事务里"这条约束一个显式的名字:任何实现都必须提供
|
||||
// CreateIdempotentWithPopularity,而不是先 Create 再补一条热度 UPDATE——
|
||||
// 后者在两条语句之间崩溃就会留下"评论在、热度不在"的半成品。
|
||||
type CommentStore interface {
|
||||
// CreateIdempotentWithPopularity 在同一个事务里完成
|
||||
// "插入评论(幂等)" + "热度增量(仅首次插入时)"。
|
||||
// created=false 表示这条意图已经落过库,调用方不得再加热度。
|
||||
// CreateIdempotentWithPopularity 在同一事务内插入评论并给热度加 delta。
|
||||
// created=false 表示该意图已落库,调用方不得再加热度。
|
||||
CreateIdempotentWithPopularity(ctx context.Context, c *Comment, delta int64) (created bool, err error)
|
||||
|
||||
GetByID(ctx context.Context, id uint) (*Comment, error)
|
||||
@@ -35,16 +23,11 @@ type CommentStore interface {
|
||||
DeleteByID(ctx context.Context, id uint) (deleted bool, err error)
|
||||
GetAllComments(ctx context.Context, videoID uint) ([]Comment, error)
|
||||
|
||||
// CreateMentions 按 DedupeKey 幂等写入提及通知。
|
||||
CreateMentions(ctx context.Context, mentions []Mention) error
|
||||
// FindAccountIDs 一次查询把用户名批量解析成账号 ID。
|
||||
FindAccountIDs(ctx context.Context, usernames []string) (map[string]uint, error)
|
||||
}
|
||||
|
||||
// nilIfEmpty 把空串转成 NULL。
|
||||
//
|
||||
// 用于 idempotency_key / dedupe_key 这类"可空唯一列":空串是一个真实的值,
|
||||
// 多条空串会互相撞唯一索引;NULL 才是"没有这个键"。
|
||||
// nilIfEmpty 供可空唯一列使用:空串会互撞,NULL 才是"没有这个键"。
|
||||
func nilIfEmpty(s string) *string {
|
||||
if s == "" {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user