Skip to content

Commit d4dc289

Browse files
Fix issue with row id for non primary key tables (#3603)
# Description of Changes When computing rowId for non primary key tables the typescript sdk incorrectly used the entire data buffer. This resulted in rowIds being incorrect when multiple rows were present within an update. # Expected complexity level and risk 1 # Testing Tested this in the context of developing the collaborator feature on the spacetime.com website. Without this change, updates to tables without primary keys were sometimes not applied to the client cache. With this update no further issues were observed. Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
1 parent 1d04930 commit d4dc289

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crates/bindings-typescript/src/sdk/db_connection_impl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ export class DbConnectionImpl<
293293
const reader = new BinaryReader(buffer);
294294
const rows: Operation[] = [];
295295
const rowType = this.#remoteModule.tables[tableName]!.rowType;
296+
let previousOffset = 0;
296297
const primaryKeyInfo =
297298
this.#remoteModule.tables[tableName]!.primaryKeyInfo;
298299
while (reader.remaining > 0) {
@@ -305,11 +306,12 @@ export class DbConnectionImpl<
305306
);
306307
} else {
307308
// Get a view of the bytes for this row.
308-
const rowBytes = buffer.subarray(0, reader.offset);
309+
const rowBytes = buffer.subarray(previousOffset, reader.offset);
309310
// Convert it to a base64 string, so we can use it as a map key.
310311
const asBase64 = fromByteArray(rowBytes);
311312
rowId = asBase64;
312313
}
314+
previousOffset = reader.offset;
313315

314316
rows.push({
315317
type,

0 commit comments

Comments
 (0)