重构:简化查询接口

- RecordQuery.QueryOldest 和 QueryNewest 不再接收 startIdx/endIdx 参数
- 查询方法返回纯 Record 列表,状态判断移到调用方
- TopicProcessor 的查询方法负责添加状态信息
- 更新所有测试文件以适配新接口
This commit is contained in:
2025-10-04 00:10:14 +08:00
parent a421ca1d85
commit 5c028a55b3
8 changed files with 168 additions and 208 deletions

View File

@@ -63,15 +63,12 @@ func main() {
}
fmt.Printf("记录总数: %d\n", count)
// 可以直接使用共享的索引获取偏移量
offset, err := index.GetOffset(5)
if err != nil {
log.Fatal(err)
}
fmt.Printf("第 5 条记录的偏移: %d\n", offset)
// 从第 5 条记录开始查询
startIndex := 5
fmt.Printf("从第 %d 条记录开始查询\n", startIndex)
// 向后查询(使用索引,高效
backward, err := query.QueryAt(offset, -1, 3, 0, offset)
// 向后查询(查询更早的记录
backward, err := query.QueryNewest(startIndex-1, 3, 0, startIndex)
if err != nil {
log.Fatal(err)
}
@@ -80,8 +77,8 @@ func main() {
fmt.Printf(" [%d] 状态=%s, 数据=%s\n", i, rws.Status, string(rws.Record.Data))
}
// 向前查询(顺序读取
forward, err := query.QueryAt(offset, 1, 3, 0, offset)
// 向前查询(查询更新的记录
forward, err := query.QueryOldest(startIndex, 3, 0, startIndex)
if err != nil {
log.Fatal(err)
}