Skip to content
This repository was archived by the owner on Jun 12, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/storage/schema/entities/EntityTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,25 @@ export class EntityTransaction extends EntityBase<TableTransaction> {
syncMap: SyncMap,
trx?: TrxToken
): Promise<{ found: boolean; eo: EntityTransaction; eiId: number }> {
const ef = verifyOneOrNone(
await storage.findTransactions({
partial: { reference: ei.reference, userId },
trx
})
)
// Prefer (userId, txid) when txid is known — txid is a globally stable
// identifier, whereas `reference` is locally-assigned by whichever
// storage first ingested the row. Two storages that independently
// internalized the same txid will hold different references, and
// matching by reference would insert a duplicate row instead of
// merging. Fall through to reference when the txid lookup misses so
// post-broadcast syncs land on an existing pre-broadcast row that
// hasn't learned its txid yet.
let ef: TableTransaction | undefined
if (ei.txid) {
ef = verifyOneOrNone(
await storage.findTransactions({ partial: { txid: ei.txid, userId }, trx })
)
}
if (!ef && ei.reference) {
ef = verifyOneOrNone(
await storage.findTransactions({ partial: { reference: ei.reference, userId }, trx })
Comment thread
sirdeggen marked this conversation as resolved.
)
}
Comment thread
sirdeggen marked this conversation as resolved.
return {
found: !!ef,
eo: new EntityTransaction(ef || { ...ei }),
Expand Down
Loading