Skip to content

Commit

Permalink
Add splice ranges back to diagnose problem
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljbruce committed Apr 19, 2024
1 parent 8f51ddf commit 5edaf82
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,40 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
};

if (lastRowKey) {
TableUtils.spliceRanges(ranges, lastRowKey);
const lessThanOrEqualTo = (lhs: string, rhs: string) =>
!TableUtils.greaterThan(lhs, rhs);

// Readjust and/or remove ranges based on previous valid row reads.
// Iterate backward since items may need to be removed.
for (let index = ranges.length - 1; index >= 0; index--) {
const range = ranges[index];
const startValue = is.object(range.start)
? (range.start as BoundData).value
: range.start;
const endValue = is.object(range.end)
? (range.end as BoundData).value
: range.end;
const startKeyIsRead =
!startValue ||
lessThanOrEqualTo(startValue as string, lastRowKey as string);
const endKeyIsNotRead =
!endValue ||
(endValue as Buffer).length === 0 ||
TableUtils.lessThan(lastRowKey as string, endValue as string);
if (startKeyIsRead) {
if (endKeyIsNotRead) {
// EndKey is not read, reset the range to start from lastRowKey open
range.start = {
value: lastRowKey,
inclusive: false,
};
} else {
// EndKey is read, remove this range
ranges.splice(index, 1);
}
}
}

rowKeys = TableUtils.getRowKeys(rowKeys, lastRowKey);

// If there was a row limit in the original request and
Expand Down

0 comments on commit 5edaf82

Please sign in to comment.