diff --git a/.changeset/green-parents-compare.md b/.changeset/green-parents-compare.md new file mode 100644 index 00000000000..42fda7dada3 --- /dev/null +++ b/.changeset/green-parents-compare.md @@ -0,0 +1,5 @@ +--- +"@firebase/firestore": patch +--- + +On browsers that support IndexedDB V3, we now invoke `transaction.commit()` to speed up data processing. diff --git a/packages/firestore/src/local/simple_db.ts b/packages/firestore/src/local/simple_db.ts index f03ac114dd5..e7120f57123 100644 --- a/packages/firestore/src/local/simple_db.ts +++ b/packages/firestore/src/local/simple_db.ts @@ -121,6 +121,16 @@ export class SimpleDbTransaction { } } + maybeCommit(): void { + // If the browser supports V3 IndexedDB, we invoke commit() explicitly to + // speed up index DB processing if the event loop remains blocks. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const maybeV3IndexedDb = this.transaction as any; + if (!this.aborted && typeof maybeV3IndexedDb.commit === 'function') { + maybeV3IndexedDb.commit(); + } + } + /** * Returns a SimpleDbStore for the specified store. All * operations performed on the SimpleDbStore happen within the context of this @@ -400,6 +410,10 @@ export class SimpleDb { objectStores ); const transactionFnResult = transactionFn(transaction) + .next(result => { + transaction.maybeCommit(); + return result; + }) .catch(error => { // Abort the transaction if there was an error. transaction.abort(error);