Skip to content

Remove MultiTabLocalStore #3436

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 3 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 6 additions & 11 deletions packages/firestore/src/core/component_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import {
} from '../local/shared_client_state';
import {
LocalStore,
MultiTabLocalStore,
newLocalStore,
newMultiTabLocalStore
synchronizeLastDocumentChangeReadTime
} from '../local/local_store';
import {
MultiTabSyncEngine,
Expand Down Expand Up @@ -133,7 +132,6 @@ export class MemoryComponentProvider implements ComponentProvider {
);
this.remoteStore.syncEngine = this.syncEngine;

await this.localStore.start();
await this.sharedClientState.start();
await this.remoteStore.start();

Expand Down Expand Up @@ -298,7 +296,6 @@ export class IndexedDbComponentProvider extends MemoryComponentProvider {
* `synchronizeTabs` will be enabled.
*/
export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvider {
localStore!: MultiTabLocalStore;
syncEngine!: MultiTabSyncEngine;

async initialize(cfg: ComponentConfiguration): Promise<void> {
Expand All @@ -318,14 +315,12 @@ export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvid
}
}
});
}

createLocalStore(cfg: ComponentConfiguration): LocalStore {
return newMultiTabLocalStore(
this.persistence,
new IndexFreeQueryEngine(),
cfg.initialUser
);
// In multi-tab mode, we need to read the last document change marker from
// persistence once during client initialization. The next call to
// `getNewDocumentChanges()` will then only read changes that were persisted
// since client startup.
await synchronizeLastDocumentChangeReadTime(this.localStore);
}

createSyncEngine(cfg: ComponentConfiguration): SyncEngine {
Expand Down
6 changes: 4 additions & 2 deletions packages/firestore/src/core/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ export class FirestoreClient {
enableNetwork(): Promise<void> {
this.verifyNotTerminated();
return this.asyncQueue.enqueue(() => {
return this.syncEngine.enableNetwork();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the FirestoreClient -> SyncEngine -> LocalStore -> Persistence indirection for enableNetwork and disableNetwork since I didn't want to come up with non-conflicting global names for the new free-standing functions.

this.persistence.setNetworkEnabled(true);
return this.remoteStore.enableNetwork();
});
}

Expand Down Expand Up @@ -334,7 +335,8 @@ export class FirestoreClient {
disableNetwork(): Promise<void> {
this.verifyNotTerminated();
return this.asyncQueue.enqueue(() => {
return this.syncEngine.disableNetwork();
this.persistence.setNetworkEnabled(false);
return this.remoteStore.disableNetwork();
});
}

Expand Down
60 changes: 12 additions & 48 deletions packages/firestore/src/core/sync_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

import { User } from '../auth/user';
import {
getNewDocumentChanges,
getCachedTarget,
ignoreIfPrimaryLeaseLoss,
LocalStore,
MultiTabLocalStore
getCurrentlyActiveClients,
lookupMutationDocuments,
removeCachedMutationBatchMetadata
} from '../local/local_store';
import { LocalViewChanges } from '../local/local_view_changes';
import { ReferenceSet } from '../local/reference_set';
Expand Down Expand Up @@ -225,10 +229,6 @@ export interface SyncEngine extends RemoteSyncer {

handleCredentialChange(user: User): Promise<void>;

enableNetwork(): Promise<void>;

disableNetwork(): Promise<void>;

getRemoteKeysForTarget(targetId: TargetId): DocumentKeySet;
}

Expand Down Expand Up @@ -940,14 +940,6 @@ class SyncEngineImpl implements SyncEngine {
}
}

enableNetwork(): Promise<void> {
return this.remoteStore.enableNetwork();
}

disableNetwork(): Promise<void> {
return this.remoteStore.disableNetwork();
}

getRemoteKeysForTarget(targetId: TargetId): DocumentKeySet {
const limboResolution = this.activeLimboResolutionsByTarget.get(targetId);
if (limboResolution && limboResolution.receivedDocument) {
Expand Down Expand Up @@ -1016,38 +1008,10 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
// `isPrimary` is true.
private _isPrimaryClient: undefined | boolean = undefined;

constructor(
protected localStore: MultiTabLocalStore,
remoteStore: RemoteStore,
datastore: Datastore,
sharedClientState: SharedClientState,
currentUser: User,
maxConcurrentLimboResolutions: number
) {
super(
localStore,
remoteStore,
datastore,
sharedClientState,
currentUser,
maxConcurrentLimboResolutions
);
}

get isPrimaryClient(): boolean {
return this._isPrimaryClient === true;
}

enableNetwork(): Promise<void> {
this.localStore.setNetworkEnabled(true);
return super.enableNetwork();
}

disableNetwork(): Promise<void> {
this.localStore.setNetworkEnabled(false);
return super.disableNetwork();
}

/**
* Reconcile the list of synced documents in an existing view with those
* from persistence.
Expand Down Expand Up @@ -1097,7 +1061,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
error?: FirestoreError
): Promise<void> {
this.assertSubscribed('applyBatchState()');
const documents = await this.localStore.lookupMutationDocuments(batchId);
const documents = await lookupMutationDocuments(this.localStore, batchId);

if (documents === null) {
// A throttled tab may not have seen the mutation before it was completed
Expand All @@ -1120,7 +1084,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
// NOTE: Both these methods are no-ops for batches that originated from
// other clients.
this.processUserCallback(batchId, error ? error : null);
this.localStore.removeCachedMutationBatchMetadata(batchId);
removeCachedMutationBatchMetadata(this.localStore, batchId);
} else {
fail(`Unknown batchState: ${batchState}`);
}
Expand Down Expand Up @@ -1236,7 +1200,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
);
// For queries that never executed on this client, we need to
// allocate the target in LocalStore and initialize a new View.
const target = await this.localStore.getTarget(targetId);
const target = await getCachedTarget(this.localStore, targetId);
debugAssert(!!target, `Target for id ${targetId} not found`);
targetData = await this.localStore.allocateTarget(target);
await this.initializeViewAndComputeSnapshot(
Expand Down Expand Up @@ -1277,7 +1241,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
}

getActiveClients(): Promise<ClientId[]> {
return this.localStore.getActiveClients();
return getCurrentlyActiveClients(this.localStore);
}

async applyTargetState(
Expand All @@ -1296,7 +1260,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
switch (state) {
case 'current':
case 'not-current': {
const changes = await this.localStore.getNewDocumentChanges();
const changes = await getNewDocumentChanges(this.localStore);
const synthesizedRemoteEvent = RemoteEvent.createSynthesizedRemoteEventForCurrentChange(
targetId,
state === 'current'
Expand Down Expand Up @@ -1336,7 +1300,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
continue;
}

const target = await this.localStore.getTarget(targetId);
const target = await getCachedTarget(this.localStore, targetId);
debugAssert(
!!target,
`Query data for active target ${targetId} not found`
Expand Down Expand Up @@ -1370,7 +1334,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
}

export function newMultiTabSyncEngine(
localStore: MultiTabLocalStore,
localStore: LocalStore,
remoteStore: RemoteStore,
datastore: Datastore,
sharedClientState: SharedClientState,
Expand Down
Loading