Skip to content

Commit 069239d

Browse files
authored
fix: throw away excess data in order to avoid delivering duplicate data (#1453)
* Do not pass duplicated data along to the user * Skip the two tests for now * Fix the mock on the row function * Remove only handlers * Remove console logs and other mock inspections * Remove import * Split the if blocks up and add a comment * Update the comment
1 parent 34d138d commit 069239d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/table.ts

+13
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,19 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
763763
callback();
764764
return;
765765
}
766+
if (TableUtils.lessThanOrEqualTo(row.id, lastRowKey)) {
767+
/*
768+
Sometimes duplicate rows reach this point. To avoid delivering
769+
duplicate rows to the user, rows are thrown away if they don't exceed
770+
the last row key. We can expect each row to reach this point and rows
771+
are delivered in order so if the last row key equals or exceeds the
772+
row id then we know data for this row has already reached this point
773+
and been delivered to the user. In this case we want to throw the row
774+
away and we do not want to deliver this row to the user again.
775+
*/
776+
callback();
777+
return;
778+
}
766779
lastRowKey = row.id;
767780
rowsRead++;
768781
callback(null, row);

test/table.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,13 @@ describe('Bigtable/Table', () => {
934934
];
935935

936936
beforeEach(() => {
937-
sinon.stub(table, 'row').callsFake(() => {
938-
return {} as Row;
937+
sinon.stub(table, 'row').callsFake((...args: unknown[]) => {
938+
return {
939+
id: args[0] as string,
940+
table: table,
941+
bigtable: table.bigtable,
942+
data: {},
943+
} as Row;
939944
});
940945
FakeChunkTransformer.prototype._transform = function (
941946
chunks: Array<{}>,

0 commit comments

Comments
 (0)