Skip to content

Commit 4069fc9

Browse files
committed
fix: significant fixes for cursorediterator and LR3 based on testing
- Change cursors to be stored back-to-front, which allows a simple `append` instead of cloning the slice, which is much better for memory - Fix context cancelation handling in the cursorediterator blocks to ensure the error is always returned to the caller - Add additional cancelation testing to the cursorediterator - Change LR3 to store the resource chunks via a cache instead of inside the cursor: this makes cursors small again and reduces serialization time immensely - Fix DB cursor handling logic bug in LR3 - Other small changes to LR3 to reduce memory usage - Reduce use of Sprintf in favor of manual concats in hot paths
1 parent 148dca7 commit 4069fc9

File tree

19 files changed

+1585
-2789
lines changed

19 files changed

+1585
-2789
lines changed

internal/cursorediterator/basics.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ type ItemAndCursor[I any] struct {
1717
Cursor Cursor
1818
}
1919

20-
func (i ItemAndCursor[I]) withCursorPrefix(prefix string) ItemAndCursor[I] {
20+
func (i ItemAndCursor[I]) withCursorHead(value string) ItemAndCursor[I] {
2121
return ItemAndCursor[I]{
2222
Item: i.Item,
23-
Cursor: i.Cursor.withPrefix(prefix),
23+
Cursor: i.Cursor.withHead(value),
2424
}
2525
}
2626

@@ -29,5 +29,11 @@ type Next[I any] func(ctx context.Context, cursor Cursor) iter.Seq2[ItemAndCurso
2929

3030
// Empty is a function that returns an empty iterator sequence.
3131
func Empty[I any](ctx context.Context, cursor Cursor) iter.Seq2[ItemAndCursor[I], error] {
32-
return func(yield func(ItemAndCursor[I], error) bool) {}
32+
return func(yield func(ItemAndCursor[I], error) bool) {
33+
// Check for context cancellation even in empty iterator
34+
if ctx.Err() != nil {
35+
_ = yield(ItemAndCursor[I]{}, ctx.Err())
36+
return
37+
}
38+
}
3339
}

0 commit comments

Comments
 (0)