背景叙述与历史取舍已写进 `docs/design/hot-ranking.md`,从源码删除。 只保留不变式与安全约束:`clientFoundRows` 禁令、唯一索引判重、 成员补零的排序约定、快照用 `RENAMENX` 只建一次、`EXPIRE` 失败即删键。 `video_service.go` 的 `NewVideoService` 注释原本复述已删方法的来历,一并收敛。 `zset.go` 的 `ZUnionStore` 与 `RenameNX` 注释各压到四行以内。 验证:go build ./... 通过。 验证:go vet ./... 通过。 验证:go test -count=1 ./... 全绿(本机无 cgo,未跑 -race)。 验证:go test -tags integration -p 1 -count=1 ./internal/feed/ ./internal/video/ ./internal/worker/ 全绿。
81 lines
2.8 KiB
Go
81 lines
2.8 KiB
Go
package feed
|
||
|
||
type FeedAuthor struct {
|
||
ID uint `json:"id"`
|
||
Username string `json:"username"`
|
||
}
|
||
|
||
type FeedVideoItem struct {
|
||
ID uint `json:"id"`
|
||
Author FeedAuthor `json:"author"`
|
||
Title string `json:"title"`
|
||
Description string `json:"description,omitempty"`
|
||
PlayURL string `json:"play_url"`
|
||
CoverURL string `json:"cover_url"`
|
||
CreateTime int64 `json:"create_time"`
|
||
LikesCount int64 `json:"likes_count"`
|
||
IsLiked bool `json:"is_liked"`
|
||
}
|
||
|
||
type ListLatestRequest struct {
|
||
Limit int `json:"limit"`
|
||
LatestTime int64 `json:"latest_time"`
|
||
}
|
||
|
||
type ListLatestResponse struct {
|
||
VideoList []FeedVideoItem `json:"video_list"`
|
||
NextTime int64 `json:"next_time"`
|
||
HasMore bool `json:"has_more"`
|
||
}
|
||
|
||
type ListLikesCountRequest struct {
|
||
Limit int `json:"limit"`
|
||
LikesCountBefore *int64 `json:"likes_count_before,omitempty"`
|
||
IDBefore *uint `json:"id_before,omitempty"`
|
||
}
|
||
|
||
type LikesCountCursor struct {
|
||
LikesCount int64
|
||
ID uint
|
||
}
|
||
|
||
type ListLikesCountResponse struct {
|
||
VideoList []FeedVideoItem `json:"video_list"`
|
||
NextLikesCountBefore *int64 `json:"next_likes_count_before,omitempty"`
|
||
NextIDBefore *uint `json:"next_id_before,omitempty"`
|
||
HasMore bool `json:"has_more"`
|
||
}
|
||
|
||
type ListByFollowingRequest struct {
|
||
Limit int `json:"limit"`
|
||
LatestTime int64 `json:"latest_time"`
|
||
}
|
||
|
||
type ListByFollowingResponse struct {
|
||
VideoList []FeedVideoItem `json:"video_list"`
|
||
NextTime int64 `json:"next_time"`
|
||
HasMore bool `json:"has_more"`
|
||
}
|
||
|
||
type ListByPopularityRequest struct {
|
||
Limit int `json:"limit"`
|
||
AsOf int64 `json:"as_of"` // 0 表示"上一个闭合分钟";只接受更早且不超过 hotSnapshotTTL 的值
|
||
Offset int `json:"offset"` // 下一页从这里开始;第一页传 0
|
||
}
|
||
|
||
type ListByPopularityResponse struct {
|
||
VideoList []FeedVideoItem `json:"video_list"`
|
||
AsOf int64 `json:"as_of"` // 本次快照的标识(分钟右端,必为已闭合分钟)
|
||
NextOffset int `json:"next_offset"`
|
||
HasMore bool `json:"has_more"`
|
||
// RankingSource 标出这一页来自哪里,同时是一个重置信号:
|
||
// "hot" Redis 快照(正常)
|
||
// "hot_db" MySQL 重算同一窗口(无快照,翻页只是近似稳定)
|
||
// "latest" 窗口内无互动,返回最新视频(终结页,HasMore 恒为 false)
|
||
// 与上一页不同即榜已换,客户端应从 offset 0 重来。
|
||
RankingSource string `json:"ranking_source"`
|
||
// SnapshotRebuilt 为 true 表示快照刚被重建(过期或被驱逐),
|
||
// 这一页可能与上一页重叠,客户端应从 offset 0 重来。
|
||
SnapshotRebuilt bool `json:"snapshot_rebuilt"`
|
||
}
|