Skip to content

Commit

Permalink
docstore/awsdynamodb: Fix Query for cases where the underlying query …
Browse files Browse the repository at this point in the history
…to AWS returns an empty set, but there's still more data
  • Loading branch information
vangent committed Mar 22, 2024
1 parent be1b4ae commit 78d0060
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions docstore/awsdynamodb/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,28 +470,29 @@ type documentIterator struct {
}

func (it *documentIterator) Next(ctx context.Context, doc driver.Document) error {
// Skip the first 'n' documents where 'n' is the offset.
if it.offset > 0 && it.count < it.offset {
it.curr++
it.count++
return it.Next(ctx, doc)
}
// Only start counting towards the limit after the offset has been reached.
if it.limit > 0 && it.count >= it.offset+it.limit || it.curr >= len(it.items) && it.last == nil {
return io.EOF
}
if it.curr >= len(it.items) {
// Make a new query request at the end of this page.
var err error
it.items, it.last, it.asFunc, err = it.qr.run(ctx, it.last)
if err != nil {
return err
for {
// Only start counting towards the limit after the offset has been reached.
if (it.limit > 0 && it.count >= it.offset+it.limit) || (it.curr >= len(it.items) && it.last == nil) {
return io.EOF
}
if it.curr >= len(it.items) {
// Make a new query request at the end of this page.
// Note that it.items can be empty, but unless if it.last is not nil
// there may be more items.
var err error
it.items, it.last, it.asFunc, err = it.qr.run(ctx, it.last)
if err != nil {
return err
}
it.curr = 0
}
// Skip the first 'n' documents where 'n' is the offset.
if it.count < it.offset {
it.curr++
it.count++
} else {
break
}
it.curr = 0
}
// If there are no more items, return EOF.
if len(it.items) == 0 {
return io.EOF
}
if err := decodeDoc(&dyn.AttributeValue{M: it.items[it.curr]}, doc); err != nil {
return err
Expand Down

0 comments on commit 78d0060

Please sign in to comment.