Skip to content

Commit c35bc8f

Browse files
Make maybeGarbageCollectMultiClientState idempotent (#2275)
1 parent 07cd70d commit c35bc8f

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

packages/firestore/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Unreleased
2+
- [changed] Improved iOS 13 support by eliminating an additional crash in our
3+
IndexedDB persistence layer.
4+
5+
# 1.6.2
26
- [changed] Fixed a crash on iOS 13 that occurred when persistence was enabled
37
in a background tab (#2232).
48
- [fixed] Fixed an issue in the interaction with the Firestore Emulator that
59
caused requests with timestamps to fail.
10+
11+
# 1.6.0
612
- [feature] Added a `Firestore.onSnapshotsInSync()` method that notifies you
713
when all your snapshot listeners are in sync with each other.
8-
9-
# 1.6.0
1014
- [fixed] Fixed a regression that caused queries with nested field filters to
1115
crash the client if the field was not present in the local copy of the
1216
document.

packages/firestore/src/local/indexeddb_persistence.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -451,33 +451,30 @@ export class IndexedDbPersistence implements Persistence {
451451
) {
452452
this.lastGarbageCollectionTime = Date.now();
453453

454-
let activeClients: DbClientMetadata[];
455-
let inactiveClients: DbClientMetadata[] = [];
456-
457-
await this.runTransaction(
454+
const inactiveClients = await this.runTransaction(
458455
'maybeGarbageCollectMultiClientState',
459-
'readwrite-primary',
456+
'readwrite-primary-idempotent',
460457
txn => {
461458
const metadataStore = IndexedDbPersistence.getStore<
462459
DbClientMetadataKey,
463460
DbClientMetadata
464461
>(txn, DbClientMetadata.store);
465462

466463
return metadataStore.loadAll().next(existingClients => {
467-
activeClients = this.filterActiveClients(
464+
const active = this.filterActiveClients(
468465
existingClients,
469466
MAX_CLIENT_AGE_MS
470467
);
471-
inactiveClients = existingClients.filter(
472-
client => activeClients.indexOf(client) === -1
468+
const inactive = existingClients.filter(
469+
client => active.indexOf(client) === -1
473470
);
474471

475472
// Delete metadata for clients that are no longer considered active.
476473
return PersistencePromise.forEach(
477-
inactiveClients,
474+
inactive,
478475
(inactiveClient: DbClientMetadata) =>
479476
metadataStore.delete(inactiveClient.clientId)
480-
);
477+
).next(() => inactive);
481478
});
482479
}
483480
);

packages/firestore/src/local/simple_db.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export class SimpleDb {
303303
isDomException(e) &&
304304
attemptNumber < TRANSACTION_RETRY_COUNT;
305305
debug(
306+
LOG_TAG,
306307
'Transaction failed with error: %s. Retrying: %s.',
307308
e.message,
308309
retryable

0 commit comments

Comments
 (0)