From 1c50d66d19a1128122e0769648a3cdc286f02406 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Fri, 12 Jan 2024 08:56:47 -0600 Subject: [PATCH] Inserts fully transactionally --- .../archivist/packages/indexeddb/src/Archivist.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/modules/packages/archivist/packages/indexeddb/src/Archivist.ts b/packages/modules/packages/archivist/packages/indexeddb/src/Archivist.ts index d61e513d330..7cab7c55655 100644 --- a/packages/modules/packages/archivist/packages/indexeddb/src/Archivist.ts +++ b/packages/modules/packages/archivist/packages/indexeddb/src/Archivist.ts @@ -116,11 +116,15 @@ export class IndexedDbArchivist< const inserted = await Promise.all( pairs.map(async ([payload, _hash]) => { const tx = this.db.transaction(this.storeName, 'readwrite') - const store = tx.objectStore(this.storeName) - const existing = await store.index(IndexedDbArchivist.hashIndexName).get(_hash) - if (!existing) { - await this.db.put(this.storeName, { ...payload, _hash }) - return payload + try { + const store = tx.objectStore(this.storeName) + const existing = await store.index(IndexedDbArchivist.hashIndexName).get(_hash) + if (!existing) { + await store.put({ ...payload, _hash }) + return payload + } + } finally { + await tx.done } }), )