2025-12-16 18:51:50 +08:00
|
|
|
|
package video
|
|
|
|
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
2026-11-01 15:15:15 +08:00
|
|
|
|
// Comment 的 (created_at, video_id) 覆盖索引 idx_comments_created_video
|
|
|
|
|
|
// 服务热榜窗口查询与 DB 回退排序:范围扫描走 created_at,video_id 留在
|
|
|
|
|
|
// 索引里避免回表。
|
2025-12-16 18:51:50 +08:00
|
|
|
|
type Comment struct {
|
|
|
|
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
|
|
|
|
Username string `gorm:"index" json:"username"`
|
2026-11-01 15:15:15 +08:00
|
|
|
|
VideoID uint `gorm:"index;index:idx_comments_created_video,priority:2" json:"video_id"`
|
2026-10-30 13:21:09 +08:00
|
|
|
|
AuthorID uint `gorm:"index;uniqueIndex:uk_comments_author_key,priority:1" json:"author_id"`
|
2025-12-16 18:51:50 +08:00
|
|
|
|
Content string `gorm:"type:text" json:"content"`
|
2026-11-01 15:15:15 +08:00
|
|
|
|
CreatedAt time.Time `gorm:"autoCreateTime;index:idx_comments_created_video,priority:1" json:"created_at"`
|
2026-10-30 13:21:09 +08:00
|
|
|
|
|
2026-10-31 00:03:53 +08:00
|
|
|
|
// IdempotencyKey 必须是 *string:空串会互撞唯一索引,NULL 不会。
|
2026-10-30 13:21:09 +08:00
|
|
|
|
IdempotencyKey *string `gorm:"column:idempotency_key;type:varchar(64);uniqueIndex:uk_comments_author_key,priority:2" json:"-"`
|
2025-12-16 18:51:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type PublishCommentRequest struct {
|
|
|
|
|
|
VideoID uint `json:"video_id"`
|
|
|
|
|
|
Content string `json:"content"`
|
2026-10-30 13:21:09 +08:00
|
|
|
|
|
2026-10-31 00:03:53 +08:00
|
|
|
|
// RequestID 由客户端为一次发送动作生成,重试时复用;为空则服务端生成。
|
2026-10-30 13:21:09 +08:00
|
|
|
|
RequestID string `json:"request_id"`
|
2025-12-16 18:51:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type DeleteCommentRequest struct {
|
|
|
|
|
|
CommentID uint `json:"comment_id"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type GetAllCommentsRequest struct {
|
|
|
|
|
|
VideoID uint `json:"video_id"`
|
|
|
|
|
|
}
|