Skip to content

Commit 5edaf82

Browse files
committed
Add splice ranges back to diagnose problem
1 parent 8f51ddf commit 5edaf82

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/table.ts

+34-1
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,40 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
811811
};
812812

813813
if (lastRowKey) {
814-
TableUtils.spliceRanges(ranges, lastRowKey);
814+
const lessThanOrEqualTo = (lhs: string, rhs: string) =>
815+
!TableUtils.greaterThan(lhs, rhs);
816+
817+
// Readjust and/or remove ranges based on previous valid row reads.
818+
// Iterate backward since items may need to be removed.
819+
for (let index = ranges.length - 1; index >= 0; index--) {
820+
const range = ranges[index];
821+
const startValue = is.object(range.start)
822+
? (range.start as BoundData).value
823+
: range.start;
824+
const endValue = is.object(range.end)
825+
? (range.end as BoundData).value
826+
: range.end;
827+
const startKeyIsRead =
828+
!startValue ||
829+
lessThanOrEqualTo(startValue as string, lastRowKey as string);
830+
const endKeyIsNotRead =
831+
!endValue ||
832+
(endValue as Buffer).length === 0 ||
833+
TableUtils.lessThan(lastRowKey as string, endValue as string);
834+
if (startKeyIsRead) {
835+
if (endKeyIsNotRead) {
836+
// EndKey is not read, reset the range to start from lastRowKey open
837+
range.start = {
838+
value: lastRowKey,
839+
inclusive: false,
840+
};
841+
} else {
842+
// EndKey is read, remove this range
843+
ranges.splice(index, 1);
844+
}
845+
}
846+
}
847+
815848
rowKeys = TableUtils.getRowKeys(rowKeys, lastRowKey);
816849

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

0 commit comments

Comments
 (0)