style(backend): 清理幂等写入路径的注释

注释只保留一行级约束。
长段理由移入设计文档。
验证:go test -count=1 ./... 全绿。
This commit is contained in:
2026-10-31 00:03:53 +08:00
parent c0ab69118a
commit c210e75996
13 changed files with 50 additions and 239 deletions

View File

@@ -1,21 +1,9 @@
// Package notification 存放通知表的实体定义。
//
// 它独立成包,是为了让"notifications 表的列结构"只有一个权威定义:
//
// - Worker 侧需要读写它(写通知、SSE 列表、标记已读、未读数);
// - video 包需要写它(评论里的 @ 提及通知)。
//
// video 不能 import worker(worker 已经 import video,会成环),而各自维护一份
// 结构体又会让列标签悄悄漂移——漂移不会报错,只会在 AutoMigrate 时试图改动
// 生产列类型。因此把实体放在两边都能引用的中立位置,依赖方向恒为
// worker → notification 与 video → notification。
//
// 本包不依赖项目内的任何其他包,只描述表结构。
// Package notification 存放 notifications 表的实体定义。
// worker 与 video 都依赖它,因此列标签只有一处。
package notification
import "time"
// Notification 是 notifications 表的一行。
type Notification struct {
ID uint `gorm:"primaryKey" json:"id"`
RecipientID uint `gorm:"index;not null" json:"recipient_id"`
@@ -26,19 +14,8 @@ type Notification struct {
IsRead bool `gorm:"default:false" json:"is_read"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
// DedupeKey 把"这条通知由哪一次用户意图产生"写进唯一索引。
//
// 同一条点赞/评论事件被投递两次(发布返回错误但实际已入队、重试、重放)时,
// 第二次会撞上 uk_notifications_dedupe 而不是再插一行——用户不会在通知
// 列表里看到两条一模一样的"点赞了你的视频",也不会收到两次 SSE 推送。
//
// 用 *string 而不是 string:没有意图键的事件(历史数据、旧客户端)宁可
// 不去重(NULL 不参与唯一约束),也不能把不同事件都判成同一条。
// DedupeKey 用 *string:无意图键的通知写 NULL,不参与唯一约束。
DedupeKey *string `gorm:"column:dedupe_key;type:varchar(128);uniqueIndex:uk_notifications_dedupe" json:"-"`
}
// TableName 固定表名。
//
// 默认命名(复数化)结果也是 notifications,但显式写出来可以避免有人把类型
// 改名之后表名跟着漂移——这张表的写入方有两个包,表名漂移的代价比多写一行大。
func (Notification) TableName() string { return "notifications" }