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 d18befa
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions docstore/awsdynamodb/query.go
Expand Up @@ -471,30 +471,34 @@ 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)
for it.count < it.offset {
if err := it.next(ctx, doc, false); err != nil {
return err

Check warning on line 476 in docstore/awsdynamodb/query.go

View check run for this annotation

Codecov / codecov/patch

docstore/awsdynamodb/query.go#L476

Added line #L476 was not covered by tests
}
}
return it.next(ctx, doc, true)
}

func (it *documentIterator) next(ctx context.Context, doc driver.Document, decode bool) error {
// 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 {
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) {
for 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
}
// 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
if decode {
if err := decodeDoc(&dyn.AttributeValue{M: it.items[it.curr]}, doc); err != nil {
return err

Check warning on line 500 in docstore/awsdynamodb/query.go

View check run for this annotation

Codecov / codecov/patch

docstore/awsdynamodb/query.go#L500

Added line #L500 was not covered by tests
}
}
it.curr++
it.count++
Expand Down

0 comments on commit d18befa

Please sign in to comment.