@@ -317,7 +317,7 @@ export class IndexedDbPersistence implements Persistence {
317
317
return this . releasePrimaryLeaseIfHeld ( txn ) ;
318
318
} else if ( this . isPrimary ) {
319
319
return this . acquireOrExtendPrimaryLease ( txn ) . next ( ( ) =>
320
- this . maybeGarbageCollectRemoteDocumentChangelog ( txn )
320
+ this . maybeGarbageCollectMultiClientState ( txn )
321
321
) ;
322
322
}
323
323
} ) ;
@@ -333,10 +333,10 @@ export class IndexedDbPersistence implements Persistence {
333
333
334
334
/**
335
335
* If the garbage collection threshold has passed, prunes the
336
- * RemoteDocumentChanges store based on the metadata state of all existing
337
- * clients.
336
+ * RemoteDocumentChanges and the ClientMetadata store based on the last update
337
+ * time of all clients.
338
338
*/
339
- private maybeGarbageCollectRemoteDocumentChangelog (
339
+ private maybeGarbageCollectMultiClientState (
340
340
txn : SimpleDbTransaction
341
341
) : PersistencePromise < void > {
342
342
assert ( this . isPrimary , 'GC should only run in the primary client' ) ;
@@ -352,12 +352,25 @@ export class IndexedDbPersistence implements Persistence {
352
352
return clientMetadataStore ( txn )
353
353
. loadAll ( )
354
354
. next ( existingClients => {
355
- // TODO(multitab): Remove outdated client metadata
356
- let activeClients = this . filterActiveClients (
355
+ const activeClients = this . filterActiveClients (
357
356
existingClients ,
358
357
CLIENT_STATE_GARBAGE_COLLECTION_THRESHOLD_MS
359
358
) ;
360
359
360
+ // Delete metadata for client that are no longer considered active.
361
+ let p = PersistencePromise . resolve ( ) ;
362
+ existingClients
363
+ . filter ( client => activeClients . indexOf ( client ) === - 1 )
364
+ . forEach ( inactiveClient => {
365
+ p = p . next ( ( ) =>
366
+ clientMetadataStore ( txn ) . delete ( inactiveClient . clientId )
367
+ ) ;
368
+ } ) ;
369
+ return p . next ( ( ) => activeClients ) ;
370
+ } )
371
+ . next ( activeClients => {
372
+ // Retrieve the minimum change ID from the set of active clients.
373
+
361
374
// The primary client doesn't read from the document change log,
362
375
// and hence we exclude it when we determine the minimum
363
376
// `lastProcessedDocumentChangeId`.
0 commit comments