docs(p0-5): 补记负 offset 与 -counters 退出码
方案里的 `ListByPopularity` 片段补上负 offset 的夹取。 `-counters` 的退出码语义写进 §8.6:修复动作不算失败,`-verify` 才算。 §9.1 的两个步骤各加一个新测试名。
This commit is contained in:
@@ -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) {
|
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())
|
asOf := lastClosedMinute(time.Now())
|
||||||
if reqAsOf > 0 {
|
if reqAsOf > 0 {
|
||||||
want := time.Unix(reqAsOf, 0).UTC().Truncate(time.Minute)
|
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
|
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. 落地清单与验证
|
||||||
|
|
||||||
### 9.1 改动清单(按 TDD 顺序)
|
### 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` |
|
| 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` 接口 |
|
| 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` |
|
| 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` |
|
| 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` 及其引用 |
|
| 9 | 删除第二条写路径 | `grep` 断言(`constants_test.go` 删断言后由 `go build` 兜底) | 删 `popularityMQ.go`/`popularityworker.go` 及其引用 |
|
||||||
|
|
||||||
删除型改动的"红"不是新测试,而是编译失败:删接口字段后 `go build ./...` 会指出所有仍在使用 `popularityMQ` 的位置,逐个清掉即可。
|
删除型改动的"红"不是新测试,而是编译失败:删接口字段后 `go build ./...` 会指出所有仍在使用 `popularityMQ` 的位置,逐个清掉即可。
|
||||||
|
|||||||
Reference in New Issue
Block a user