Skip to content

Remove MultiTabSyncEngine #3442

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 4 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
50 changes: 26 additions & 24 deletions packages/firestore/src/core/component_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ import {
synchronizeLastDocumentChangeReadTime
} from '../local/local_store';
import {
MultiTabSyncEngine,
newMultiTabSyncEngine,
applyActiveTargetsChange,
applyBatchState,
applyPrimaryState,
applyTargetState,
getActiveClients,
newSyncEngine,
SyncEngine
} from './sync_engine';
Expand All @@ -46,9 +49,9 @@ import { OnlineStateSource } from './types';
import { LruParams, LruScheduler } from '../local/lru_garbage_collector';
import { IndexFreeQueryEngine } from '../local/index_free_query_engine';
import {
indexedDbStoragePrefix,
indexedDbClearPersistence,
IndexedDbPersistence,
indexedDbClearPersistence
indexedDbStoragePrefix
} from '../local/indexeddb_persistence';
import {
MemoryEagerDelegate,
Expand All @@ -59,6 +62,7 @@ import { newSerializer } from '../platform/serializer';
import { getDocument, getWindow } from '../platform/dom';
import { CredentialsProvider } from '../api/credentials';
import { Connection } from '../remote/connection';

const MEMORY_ONLY_PERSISTENCE_ERROR_MESSAGE =
'You are using the memory-only build of Firestore. Persistence support is ' +
'only available via the @firebase/firestore bundle or the ' +
Expand Down Expand Up @@ -200,7 +204,8 @@ export class MemoryComponentProvider implements ComponentProvider {
this.datastore,
this.sharedClientState,
cfg.initialUser,
cfg.maxConcurrentLimboResolutions
cfg.maxConcurrentLimboResolutions,
/* isPrimary= */ true
);
}

Expand Down Expand Up @@ -229,17 +234,6 @@ export class IndexedDbComponentProvider extends MemoryComponentProvider {
);
}

createSyncEngine(cfg: ComponentConfiguration): SyncEngine {
return newSyncEngine(
this.localStore,
this.remoteStore,
this.datastore,
this.sharedClientState,
cfg.initialUser,
cfg.maxConcurrentLimboResolutions
);
}

createGarbageCollectionScheduler(
cfg: ComponentConfiguration
): GarbageCollectionScheduler | null {
Expand Down Expand Up @@ -296,17 +290,13 @@ export class IndexedDbComponentProvider extends MemoryComponentProvider {
* `synchronizeTabs` will be enabled.
*/
export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvider {
syncEngine!: MultiTabSyncEngine;

async initialize(cfg: ComponentConfiguration): Promise<void> {
await super.initialize(cfg);

// 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 (this.syncEngine as MultiTabSyncEngine).applyPrimaryState(
isPrimary
);
await applyPrimaryState(this.syncEngine, isPrimary);
if (this.gcScheduler) {
if (isPrimary && !this.gcScheduler.started) {
this.gcScheduler.start(this.localStore);
Expand All @@ -324,16 +314,28 @@ export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvid
}

createSyncEngine(cfg: ComponentConfiguration): SyncEngine {
const syncEngine = newMultiTabSyncEngine(
const startsAsPrimary =
!cfg.persistenceSettings.durable ||
!cfg.persistenceSettings.synchronizeTabs;
const syncEngine = newSyncEngine(
this.localStore,
this.remoteStore,
this.datastore,
this.sharedClientState,
cfg.initialUser,
cfg.maxConcurrentLimboResolutions
cfg.maxConcurrentLimboResolutions,
startsAsPrimary
);
if (this.sharedClientState instanceof WebStorageSharedClientState) {
this.sharedClientState.syncEngine = syncEngine;
this.sharedClientState.syncEngine = {
applyBatchState: applyBatchState.bind(null, syncEngine),
applyTargetState: applyTargetState.bind(null, syncEngine),
applyActiveTargetsChange: applyActiveTargetsChange.bind(
null,
syncEngine
),
getActiveClients: getActiveClients.bind(null, syncEngine)
};
}
return syncEngine;
}
Expand Down
Loading