style(backend): 清理幂等写入路径的注释
注释只保留一行级约束。 长段理由移入设计文档。 验证:go test -count=1 ./... 全绿。
This commit is contained in:
@@ -10,18 +10,7 @@ type Comment struct {
|
||||
Content string `gorm:"type:text" json:"content"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
|
||||
// IdempotencyKey 是"这次发评论的意图"的稳定标识(P0-4)。
|
||||
//
|
||||
// 与 AuthorID 组成唯一索引 uk_comments_author_key:同一次用户意图
|
||||
// 无论被写入几次(MQ 假失败后的 DB 兜底、worker 重复投递、客户端
|
||||
// 重试),在数据库里都只会留下一行。
|
||||
//
|
||||
// 必须是指针:MySQL 的唯一索引不约束 NULL,多个 NULL 可以共存。
|
||||
// 若用 string + 空串,存量行与"没带 request_id"的行会全部撞在
|
||||
// 同一个 '' 上,第二条无键评论就会被判成重复。
|
||||
//
|
||||
// json:"-" 让它不出现在任何 API 响应里:它是去重机制的内部标识,
|
||||
// 不是用户可见的数据。
|
||||
// IdempotencyKey 必须是 *string:空串会互撞唯一索引,NULL 不会。
|
||||
IdempotencyKey *string `gorm:"column:idempotency_key;type:varchar(64);uniqueIndex:uk_comments_author_key,priority:2" json:"-"`
|
||||
}
|
||||
|
||||
@@ -29,11 +18,7 @@ type PublishCommentRequest struct {
|
||||
VideoID uint `json:"video_id"`
|
||||
Content string `json:"content"`
|
||||
|
||||
// RequestID 由客户端为"一次发送动作"生成,重试时复用同一个值。
|
||||
//
|
||||
// 为空时服务端会生成一个(单次请求内仍然幂等,但客户端重试无法被识别)。
|
||||
// 校验规则见 idempotency.go:8–64 个 [0-9a-zA-Z_-] 字符,非法值返回 400
|
||||
// 而不是静默截断或忽略。
|
||||
// RequestID 由客户端为一次发送动作生成,重试时复用;为空则服务端生成。
|
||||
RequestID string `json:"request_id"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user