style(backend): 清理幂等写入路径的注释
注释只保留一行级约束。 长段理由移入设计文档。 验证:go test -count=1 ./... 全绿。
This commit is contained in:
@@ -62,7 +62,7 @@ func (w *CommentWorker) applyPublish(ctx context.Context, evt *rabbitmq.CommentE
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
// 视频已被删除:没有可落评论的地方,但这是"处理完了",不是失败。
|
||||
// 视频已删除:处理完了,不是失败。
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -72,8 +72,7 @@ func (w *CommentWorker) applyPublish(ctx context.Context, evt *rabbitmq.CommentE
|
||||
AuthorID: evt.AuthorID,
|
||||
Content: strings.TrimSpace(evt.Content),
|
||||
}
|
||||
// 事件里的 event_id 就是"这次用户意图"的键。API 侧若已经兜底直写过,
|
||||
// 这次插入会命中唯一索引:(created=false) 说明重复投递,热度不能再加一次。
|
||||
// event_id 即意图键:API 已直写时这里会命中唯一索引。
|
||||
if evt.EventID != "" {
|
||||
key := evt.EventID
|
||||
c.IdempotencyKey = &key
|
||||
|
||||
@@ -16,12 +16,7 @@ import (
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
// notificationActions 记录每个通知队列期望收到哪种 action。
|
||||
//
|
||||
// 分派依据必须是队列 + 消息体里的 action,不能是 routing key:重试链路
|
||||
// 回源时会把 routing key 改写成队列名(`like.like` → `notification.like`),
|
||||
// 按 routing key 判断会让第二次投递变成"未知事件"而被立即停泊,重试预算
|
||||
// 白丢。queue 在整个生命周期里不变,所以它是可靠的。
|
||||
// 分派必须用队列 + body.action:重试回源会把 routing key 改写成队列名。
|
||||
var notificationActions = map[string]string{
|
||||
rabbitmq.NotificationLikeQueue: "like",
|
||||
rabbitmq.NotificationCommentQueue: "publish",
|
||||
@@ -51,10 +46,7 @@ func (w *NotificationWorker) Run(ctx context.Context) error {
|
||||
if w.queue == "" {
|
||||
return errors.New("queue is required")
|
||||
}
|
||||
// 这里刻意不再 AutoMigrate:建表由 API 进程的 db.AutoMigrate 统一负责
|
||||
// (internal/db/db.go 已包含 ¬ification.Notification{})。原来每个通知消费者
|
||||
// 各跑一次 AutoMigrate,加唯一索引后三个 goroutine 会并发 CREATE INDEX
|
||||
// 并撞上 1061;即使能靠重连自愈,也让"谁来建表"出现了两个答案。
|
||||
// 建表由 API 进程的 db.AutoMigrate 统一负责;三个消费者并发建索引会撞 1061。
|
||||
return rabbitmq.ConsumeLoop(ctx, w.ch, w.parker, w.queue, rabbitmq.MaxAttempts, w.process)
|
||||
}
|
||||
|
||||
@@ -165,10 +157,7 @@ func (w *NotificationWorker) videoAuthorID(ctx context.Context, videoID uint) (u
|
||||
}
|
||||
|
||||
func (w *NotificationWorker) persist(ctx context.Context, notif *notification.Notification, eventID string) error {
|
||||
// 意图键取自事件体里的 event_id:P0-4 之后它就是"这一次用户动作"的
|
||||
// 稳定标识(发布端用意图键填充)。取不到时留空——结果是不去重,
|
||||
// 这是刻意的保守选择:多一条通知可以接受,把两条不同事件判成同一条
|
||||
// 会让用户永久收不到其中一条。
|
||||
// event_id 取不到时留空,此时该通知不参与去重。
|
||||
notif.DedupeKey = nilIfEmpty(video.NotificationDedupeKey(notif.Type, eventID, notif.RecipientID))
|
||||
|
||||
res := w.db.WithContext(ctx).
|
||||
|
||||
Reference in New Issue
Block a user