Skip to content

Commit 6b2730d

Browse files
Merge 42ea106 into bf93a38
2 parents bf93a38 + 42ea106 commit 6b2730d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

.changeset/green-parents-compare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/firestore": patch
3+
---
4+
5+
On browsers that support IndexedDB V3, we now invoke `transaction.commit()` to speed up data processing.

packages/firestore/src/local/simple_db.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ export class SimpleDbTransaction {
121121
}
122122
}
123123

124+
maybeCommit(): void {
125+
// If the browser supports V3 IndexedDB, we invoke commit() explicitly to
126+
// speed up index DB processing if the event loop remains blocks.
127+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
128+
const maybeV3IndexedDb = this.transaction as any;
129+
if (!this.aborted && typeof maybeV3IndexedDb.commit === 'function') {
130+
maybeV3IndexedDb.commit();
131+
}
132+
}
133+
124134
/**
125135
* Returns a SimpleDbStore<KeyType, ValueType> for the specified store. All
126136
* operations performed on the SimpleDbStore happen within the context of this
@@ -400,6 +410,10 @@ export class SimpleDb {
400410
objectStores
401411
);
402412
const transactionFnResult = transactionFn(transaction)
413+
.next(result => {
414+
transaction.maybeCommit();
415+
return result;
416+
})
403417
.catch(error => {
404418
// Abort the transaction if there was an error.
405419
transaction.abort(error);

0 commit comments

Comments
 (0)