feat(feed): 热榜读路径收口到闭合分钟的只建一次快照
窗口右端改为上一个已闭合分钟。当前分钟仍在增长,不能当右端。 一个 as_of 的快照只建一次。ZUNIONSTORE 先写临时键,再用 RENAMENX 原子占位,抢不到的人读赢家。 空并集不再发布成快照。否则这个 as_of 在 TTL 内每次都会命中一张空表,却报告 snapshot_rebuilt=false。 快照 TTL 改为 1 小时。EXPIRE 失败时删掉 dest,避免它继承临时键的 1 分钟寿命而永远翻不到第 2 页。 NextOffset 按 len(members) 推进。视频被删除后 member 仍在,按存活视频数推进会重复读到已跳过的位置。 DB 回退改用 ListHotWindow 重算同一窗口。排序为 score DESC, video_id DESC,与 ZSET 一致。 窗口内无互动时返回 latest。这一支是终结页,NextOffset 为 0。 ZUnionStore 返回并集基数,供调用方判空。新增 RenameNX 包装方法。 删除旧游标字段与 latest_* 配对校验。请求只剩 limit、as_of、offset。 验证:go build -buildvcs=false ./... 通过。go test -buildvcs=false -count=1 ./... 全绿。
This commit is contained in:
@@ -131,34 +131,12 @@ func (f *FeedHandler) ListByPopularity(c *gin.Context) {
|
||||
viewerAccountID = 0
|
||||
}
|
||||
|
||||
var latestPopularity int64
|
||||
var latestBefore time.Time
|
||||
var latestIDBefore uint
|
||||
|
||||
if req.LatestPopularity < 0 {
|
||||
c.JSON(400, gin.H{"error": "latest_popularity must be >= 0"})
|
||||
return
|
||||
}
|
||||
|
||||
anyCursor := !req.LatestBefore.IsZero() || req.LatestIDBefore != nil
|
||||
if anyCursor {
|
||||
if req.LatestBefore.IsZero() || req.LatestIDBefore == nil || *req.LatestIDBefore == 0 {
|
||||
c.JSON(400, gin.H{"error": "latest_before and latest_id_before must be provided together"})
|
||||
return
|
||||
}
|
||||
latestPopularity = req.LatestPopularity
|
||||
latestBefore = req.LatestBefore
|
||||
latestIDBefore = *req.LatestIDBefore
|
||||
}
|
||||
resp, err := f.service.ListByPopularity(
|
||||
c.Request.Context(),
|
||||
req.Limit,
|
||||
req.AsOf,
|
||||
req.Offset,
|
||||
viewerAccountID,
|
||||
latestPopularity,
|
||||
latestBefore,
|
||||
latestIDBefore,
|
||||
)
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"error": err.Error()})
|
||||
|
||||
Reference in New Issue
Block a user