Skip to content

Commit

Permalink
Inserts fully transactionally
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Jan 12, 2024
1 parent 213a7a2 commit 1c50d66
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}),
)
Expand Down

0 comments on commit 1c50d66

Please sign in to comment.