Skip to content

Use transaction.commit() if available #5982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-parents-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/firestore": patch
---

On browsers that support IndexedDB V3, we now invoke `transaction.commit()` to speed up data processing.
14 changes: 14 additions & 0 deletions packages/firestore/src/local/simple_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyType, ValueType> for the specified store. All
* operations performed on the SimpleDbStore happen within the context of this
Expand Down Expand Up @@ -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);
Expand Down