主题
评论模块(internal/comment)支持父子结构评论、附件、敏感词审核与异步批量落库,与互动模块共用「Redis 实时 + 异步落库」的节奏。
internal/comment
video_comments
parent_id
comment_likes
files
发送评论 ──▶ 敏感词过滤(AC 自动机) ├─ 命中 → 拒绝(或标记待审核) ▼ 写 Redis(实时可见 + 计数) ▼ 投 Kafka[comment](异步落库) ▼ worker 消费 → 事务写 DB(幂等)
video_comments.parent_id
NULL
internal/comment/moderation.go
filter.Contains(content)
ErrSensitive
与点赞/播放量相同的 Flusher 模式:
// internal/comment/counter.go type Flusher struct { rdb *redis.Client db *gorm.DB opts Options // FlushInterval(5s) / FlushBatch(200) }
flush_interval
flush_batch
comment:count:{videoID}
videos
RefType = video_comment
/api/v1/videos/{id}/comments
/api/v1/comments/{id}
/api/v1/comments/{id}/like
[comment] enabled = true flush_interval = 5 # 落库间隔(秒) flush_batch = 200 # 批量落库阈值
评论系统
评论模块(
internal/comment)支持父子结构评论、附件、敏感词审核与异步批量落库,与互动模块共用「Redis 实时 + 异步落库」的节奏。数据模型
video_commentsparent_id支持父子结构)comment_likesfiles整体流程
2
3
4
5
6
7
8
核心设计
1. 父子评论
video_comments.parent_id为NULL表示根评论,非空表示回复;2. 敏感词审核
internal/comment/moderation.go);filter.Contains(content)命中即拒绝(与弹幕一致的ErrSensitive语义)。3. 异步批量落库
与点赞/播放量相同的 Flusher 模式:
2
3
4
5
6
flush_interval秒或满flush_batch条,批量事务落库;4. 评论计数
comment:count:{videoID});videos表冗余列。5. 附件
files表(RefType = video_comment等);接口
/api/v1/videos/{id}/comments/api/v1/videos/{id}/comments/api/v1/comments/{id}/api/v1/comments/{id}/like配置
2
3
4
演进方向