From c5e2f0e30b585934ffae18a916b6732f0df8c429 Mon Sep 17 00:00:00 2001 From: huanghaosheng <386998068@qq.com> Date: Sun, 1 Nov 2026 16:25:17 +0800 Subject: [PATCH] =?UTF-8?q?docs(p0-5):=20=E8=A1=A5=E8=AE=B0=E8=B4=9F=20off?= =?UTF-8?q?set=20=E4=B8=8E=20-counters=20=E9=80=80=E5=87=BA=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 方案里的 `ListByPopularity` 片段补上负 offset 的夹取。 `-counters` 的退出码语义写进 §8.6:修复动作不算失败,`-verify` 才算。 §9.1 的两个步骤各加一个新测试名。 --- docs/solutions/P0-5-popularity-single-source.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/solutions/P0-5-popularity-single-source.md b/docs/solutions/P0-5-popularity-single-source.md index 34f8768..caa3c7b 100644 --- a/docs/solutions/P0-5-popularity-single-source.md +++ b/docs/solutions/P0-5-popularity-single-source.md @@ -893,6 +893,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) @@ -1674,6 +1681,8 @@ CONFIG_PATH=configs/config.compose-local.yaml go run ./cmd/reconcile -counters go run ./cmd/reconcile -counters -limit 500 >> /var/log/vloop-reconcile.log 2>&1 ``` +退出码只有两种含义,别混用。`-verify` 是**只读检查**,`drift > 0` 就是 `exit 1`——"有漂移"正是它要报告的东西。`-counters` 是**修复动作**,只有"这次巡检没做成"(连不上库、事务失败)才 `exit 1`;修好了多少条走日志(`fixed=N`),不改变退出码。否则每天的定时修复都会告警,而告警本身就失去意义。 + ## 9. 落地清单与验证 ### 9.1 改动清单(按 TDD 顺序) @@ -1687,9 +1696,9 @@ CONFIG_PATH=configs/config.compose-local.yaml go run ./cmd/reconcile -counters | 3 | 点赞单事务 | `backend/internal/video/like_repo_integration_test.go`:`TestApplyLike_InsertsAndCountsOnce`、`TestApplyLike_DuplicateDoesNotCount`、`TestApplyUnlike_RestoresOriginalBucket` | `ApplyLike`/`ApplyUnlike` | | 4 | 评论删除回退 | `backend/internal/video/comment_repo_integration_test.go` 增 `TestDeleteWithPopularity_DecrementsOnce` | `DeleteWithPopularity` + `CommentStore` 接口 | | 5 | worker 分发 | `backend/internal/worker/likeworker_integration_test.go`(新):`TestLikeWorker_ReplayDoesNotDoubleHot`、`TestCommentWorker_DeleteRevertsHot`。worker 持有 `*video.LikeRepository` 这种具体类型,仓库既无 DB mock 也不为测试引入接口,因此按 `AGENTS.md` 的"MySQL 没有 mock"走真实库 + `//go:build integration` | `likeworker.go` / `commentworker.go` | -| 6 | 读路径口径 | 纯函数部分放 `backend/internal/feed/service_test.go`(新):`TestLastClosedMinute_NeverReturnsOpenMinute`、`TestHotWindowBounds_Covers60Buckets`、`TestListByPopularity_StaleAsOfIsReplaced`;翻页、快照与回退需要 `GetByIDs` 打 DB,放 `backend/internal/feed/service_integration_test.go`:`TestListByPopularity_PaginatesWithoutOverlap`、`TestListByPopularity_SnapshotIsBuiltOnce`、`TestListByPopularity_LateDeltaDoesNotChangeSnapshot`、`TestListByPopularity_FallsBackToDBWindow`、`TestListByPopularity_LatestBranchIsTerminal`(`latest` 必须 `NextOffset=0`/`HasMore=false`)、`TestListByPopularity_EmptyUnionIsNotPublished`(60 个空桶不得留下空快照)、`TestListByPopularity_SnapshotExpireFailureDropsKey` | `feed/service.go` 的 `lastClosedMinute`/`hotWindowBounds`/两条路径 | +| 6 | 读路径口径 | 纯函数部分放 `backend/internal/feed/service_test.go`(新):`TestLastClosedMinute_NeverReturnsOpenMinute`、`TestHotWindowBounds_Covers60Buckets`、`TestListByPopularity_StaleAsOfIsReplaced`;翻页、快照与回退需要 `GetByIDs` 打 DB,放 `backend/internal/feed/service_integration_test.go`:`TestListByPopularity_PaginatesWithoutOverlap`、`TestListByPopularity_SnapshotIsBuiltOnce`、`TestListByPopularity_LateDeltaDoesNotChangeSnapshot`、`TestListByPopularity_FallsBackToDBWindow`、`TestListByPopularity_LatestBranchIsTerminal`(`latest` 必须 `NextOffset=0`/`HasMore=false`)、`TestListByPopularity_EmptyUnionIsNotPublished`(60 个空桶不得留下空快照)、`TestListByPopularity_SnapshotExpireFailureDropsKey`、`TestListByPopularity_NegativeOffsetIsClamped`(负游标夹到 0,不能让它走到 SQL 的 `OFFSET -1`) | `feed/service.go` 的 `lastClosedMinute`/`hotWindowBounds`/两条路径 | | 7 | DB 窗口 SQL | `backend/internal/feed/repo_integration_test.go`:`TestListHotWindow_OrdersByScoreThenIDDesc` | `ListHotWindow` | -| 8 | 对账 | `backend/internal/video/counters_reconcile_integration_test.go`:`TestReconcile_FixesDrift` | `counters_reconcile.go` | +| 8 | 对账 | `backend/internal/video/counters_reconcile_integration_test.go`:`TestReconcile_FixesDrift`;退出码语义放 `backend/cmd/reconcile/main_test.go`:`TestCountersResult_RepairedDriftIsNotFailure` | `counters_reconcile.go`、`cmd/reconcile/main.go` 的 `countersResult` | | 9 | 删除第二条写路径 | `grep` 断言(`constants_test.go` 删断言后由 `go build` 兜底) | 删 `popularityMQ.go`/`popularityworker.go` 及其引用 | 删除型改动的"红"不是新测试,而是编译失败:删接口字段后 `go build ./...` 会指出所有仍在使用 `popularityMQ` 的位置,逐个清掉即可。