修复:统一查询方法的返回顺序为索引递增

重要变更:
- QueryOldest 和 QueryNewest 现在都返回按索引递增排序的结果
- 移除了 QueryNewest 中的结果反转操作(line 184-187)

方法行为说明:
- QueryOldest(startIndex, count): 从 startIndex 向索引递增方向查询
- QueryNewest(endIndex, count): 从 endIndex 向索引递减方向查询
- 两者返回结果都按索引递增方向排序(一致性)

更新内容:
1. query.go:
   - 移除 QueryNewest 的反转操作
   - 更新两个方法的注释
2. topic_processor.go: 更新注释与实现一致
3. seqlog_test.go: 更新测试预期结果
4. example/index/main.go: 更新注释和输出说明

测试验证:
- 所有测试通过(go test ./... -short)
- 示例编译成功

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-04 11:55:44 +08:00
parent 9b7a9c2734
commit dfdc27c67f
4 changed files with 26 additions and 34 deletions

View File

@@ -69,22 +69,24 @@ func main() {
startIndex := 5
fmt.Printf("从第 %d 条记录开始查询\n", startIndex)
// 向查询(查询更早的记录)
// 向索引递减方向查询(查询更早的记录)
// QueryNewest(4, 3) 查询索引 2, 3, 4返回按索引递增排序
backward, err := query.QueryNewest(startIndex-1, 3)
if err != nil {
log.Fatal(err)
}
fmt.Printf("向查询 3 条记录:\n")
fmt.Printf("向索引递减方向查询 3 条记录(索引 2-4:\n")
for i, rec := range backward {
fmt.Printf(" [%d] 数据=%s\n", i, string(rec.Data))
}
// 向查询(查询更新的记录)
// 向索引递增方向查询(查询更新的记录)
// QueryOldest(5, 3) 查询索引 5, 6, 7返回按索引递增排序
forward, err := query.QueryOldest(startIndex, 3)
if err != nil {
log.Fatal(err)
}
fmt.Printf("向查询 3 条记录:\n")
fmt.Printf("向索引递增方向查询 3 条记录(索引 5-7:\n")
for i, rec := range forward {
fmt.Printf(" [%d] 数据=%s\n", i, string(rec.Data))
}