Skip to content

Commit f5ac47f

Browse files
Use transaction.commit() if available (#5982)
* Call commit() if available * Create green-parents-compare.md * Comment * Lint * Don't commit when aborted
1 parent e961968 commit f5ac47f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

.changeset/green-parents-compare.md

+5
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

+14
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)