From edeba7784cc67a44867843ee06ef3bad15730ade Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 12 Aug 2021 11:57:09 -0600 Subject: [PATCH 1/3] Run LRU even if multi-tab is disabled --- .../firestore/src/core/component_provider.ts | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/firestore/src/core/component_provider.ts b/packages/firestore/src/core/component_provider.ts index 0c5340318f3..bf8ab3e8c02 100644 --- a/packages/firestore/src/core/component_provider.ts +++ b/packages/firestore/src/core/component_provider.ts @@ -182,6 +182,22 @@ export class IndexedDbOfflineComponentProvider extends MemoryOfflineComponentPro this.onlineComponentProvider.syncEngine ); await fillWritePipeline(this.onlineComponentProvider.remoteStore); + + // NOTE: This will immediately call the listener, so we make sure to + // set it after localStore / remoteStore are started. + await this.persistence.setPrimaryStateListener(async isPrimary => { + await syncEngineApplyPrimaryState( + this.onlineComponentProvider.syncEngine, + isPrimary + ); + if (this.gcScheduler) { + if (isPrimary && !this.gcScheduler.started) { + this.gcScheduler.start(this.localStore); + } else if (!isPrimary) { + this.gcScheduler.stop(); + } + } + }); } createLocalStore(cfg: ComponentConfiguration): LocalStore { @@ -267,22 +283,6 @@ export class MultiTabOfflineComponentProvider extends IndexedDbOfflineComponentP }; await this.sharedClientState.start(); } - - // NOTE: This will immediately call the listener, so we make sure to - // set it after localStore / remoteStore are started. - await this.persistence.setPrimaryStateListener(async isPrimary => { - await syncEngineApplyPrimaryState( - this.onlineComponentProvider.syncEngine, - isPrimary - ); - if (this.gcScheduler) { - if (isPrimary && !this.gcScheduler.started) { - this.gcScheduler.start(this.localStore); - } else if (!isPrimary) { - this.gcScheduler.stop(); - } - } - }); } createSharedClientState(cfg: ComponentConfiguration): SharedClientState { From afad725ca31b193b1daa7d643be77cd8b1c0849e Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 12 Aug 2021 11:59:41 -0600 Subject: [PATCH 2/3] Create witty-chicken-mate.md --- .changeset/witty-chicken-mate.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/witty-chicken-mate.md diff --git a/.changeset/witty-chicken-mate.md b/.changeset/witty-chicken-mate.md new file mode 100644 index 00000000000..5b667170355 --- /dev/null +++ b/.changeset/witty-chicken-mate.md @@ -0,0 +1,5 @@ +--- +"@firebase/firestore": patch +--- + +Fixed a regression that prevented the garbage collector from running if multi-tab was disabled. From ee12bb1a7ca9b9a907ab6312452c32232ac86cf6 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 17 Aug 2021 10:10:52 -0600 Subject: [PATCH 3/3] Fix CI --- .../firestore/src/core/component_provider.ts | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/firestore/src/core/component_provider.ts b/packages/firestore/src/core/component_provider.ts index bf8ab3e8c02..2bf13fc33e0 100644 --- a/packages/firestore/src/core/component_provider.ts +++ b/packages/firestore/src/core/component_provider.ts @@ -185,18 +185,11 @@ export class IndexedDbOfflineComponentProvider extends MemoryOfflineComponentPro // NOTE: This will immediately call the listener, so we make sure to // set it after localStore / remoteStore are started. - await this.persistence.setPrimaryStateListener(async isPrimary => { - await syncEngineApplyPrimaryState( - this.onlineComponentProvider.syncEngine, - isPrimary - ); - if (this.gcScheduler) { - if (isPrimary && !this.gcScheduler.started) { + await this.persistence.setPrimaryStateListener(() => { + if (this.gcScheduler && !this.gcScheduler.started) { this.gcScheduler.start(this.localStore); - } else if (!isPrimary) { - this.gcScheduler.stop(); - } } + return Promise.resolve(); }); } @@ -283,6 +276,22 @@ export class MultiTabOfflineComponentProvider extends IndexedDbOfflineComponentP }; await this.sharedClientState.start(); } + + // NOTE: This will immediately call the listener, so we make sure to + // set it after localStore / remoteStore are started. + await this.persistence.setPrimaryStateListener(async isPrimary => { + await syncEngineApplyPrimaryState( + this.onlineComponentProvider.syncEngine, + isPrimary + ); + if (this.gcScheduler) { + if (isPrimary && !this.gcScheduler.started) { + this.gcScheduler.start(this.localStore); + } else if (!isPrimary) { + this.gcScheduler.stop(); + } + } + }); } createSharedClientState(cfg: ComponentConfiguration): SharedClientState {