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

重要变更:
- 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

@@ -339,10 +339,10 @@ func (tp *TopicProcessor) Query() *RecordQuery {
return tp.query
}
// QueryOldest 从指定索引开始查询记录(向前读取)
// QueryOldest 从指定索引向索引递增方向查询记录
// startIndex: 查询起始索引
// count: 查询数量
// 返回的记录包含状态信息(基于 tailer 的窗口索引),按时间顺序(索引递增方向
// 返回的记录包含状态信息(基于 tailer 的窗口索引),按索引递增方向排序
func (tp *TopicProcessor) QueryOldest(startIndex, count int) ([]*RecordWithStatus, error) {
// 查询记录
records, err := tp.query.QueryOldest(startIndex, count)
@@ -371,10 +371,10 @@ func (tp *TopicProcessor) QueryOldest(startIndex, count int) ([]*RecordWithStatu
return results, nil
}
// QueryNewest 从指定索引开始向后查询记录(索引递减方向
// endIndex: 查询结束索引(最新的记录)
// QueryNewest 从指定索引索引递减方向查询记录
// endIndex: 查询的最大索引(向前查询更早的记录)
// count: 查询数量
// 返回的记录包含状态信息(基于 tailer 的窗口索引),按时间倒序(最新在前)
// 返回的记录包含状态信息(基于 tailer 的窗口索引),按索引递增方向排序
func (tp *TopicProcessor) QueryNewest(endIndex, count int) ([]*RecordWithStatus, error) {
// 查询记录
records, err := tp.query.QueryNewest(endIndex, count)