fix(feed): 把负 offset 夹到 0
负 offset 是非法游标。它一路走到 SQL 的 OFFSET 参数。 MySQL 抛 Error 1690,一次翻页请求变成 500。 入口夹一次就够:这个值同时喂给 Redis 的 LIMIT 与 SQL 的 OFFSET。 不放 handler 是因为 handler 只规整 limit,夹在服务层才能挡住所有调用方。 验证:go test -tags integration -p 1 -count=1 ./internal/feed/ 全绿
This commit is contained in:
@@ -461,6 +461,13 @@ func hotWindowBounds(asOf time.Time) (from, to time.Time) {
|
||||
}
|
||||
|
||||
func (f *FeedService) ListByPopularity(ctx context.Context, limit int, reqAsOf int64, offset int, viewerAccountID uint) (ListByPopularityResponse, error) {
|
||||
// offset 是榜内位置,负数没有意义。夹在入口而不是只夹在 handler:
|
||||
// 它同时喂给 Redis 的 LIMIT 与 SQL 的 OFFSET,而后者拿到 -1 会直接
|
||||
// 报错(Error 1690),把一个"翻到头了"的请求变成 500。
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
|
||||
asOf := lastClosedMinute(time.Now())
|
||||
if reqAsOf > 0 {
|
||||
want := time.Unix(reqAsOf, 0).UTC().Truncate(time.Minute)
|
||||
|
||||
Reference in New Issue
Block a user