Skip to content

Commit 41ea951

Browse files
Remove MultiTabLocalStore
1 parent ee33ebf commit 41ea951

File tree

9 files changed

+170
-217
lines changed

9 files changed

+170
-217
lines changed

packages/firestore/src/core/component_provider.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ import {
2323
} from '../local/shared_client_state';
2424
import {
2525
LocalStore,
26-
MultiTabLocalStore,
2726
newLocalStore,
28-
newMultiTabLocalStore
27+
synchronizeLastDocumentChangeReadTime
2928
} from '../local/local_store';
3029
import {
3130
MultiTabSyncEngine,
@@ -133,7 +132,6 @@ export class MemoryComponentProvider implements ComponentProvider {
133132
);
134133
this.remoteStore.syncEngine = this.syncEngine;
135134

136-
await this.localStore.start();
137135
await this.sharedClientState.start();
138136
await this.remoteStore.start();
139137

@@ -298,7 +296,6 @@ export class IndexedDbComponentProvider extends MemoryComponentProvider {
298296
* `synchronizeTabs` will be enabled.
299297
*/
300298
export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvider {
301-
localStore!: MultiTabLocalStore;
302299
syncEngine!: MultiTabSyncEngine;
303300

304301
async initialize(cfg: ComponentConfiguration): Promise<void> {
@@ -318,14 +315,12 @@ export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvid
318315
}
319316
}
320317
});
321-
}
322318

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

331326
createSyncEngine(cfg: ComponentConfiguration): SyncEngine {

packages/firestore/src/core/firestore_client.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ export class FirestoreClient {
202202
enableNetwork(): Promise<void> {
203203
this.verifyNotTerminated();
204204
return this.asyncQueue.enqueue(() => {
205-
return this.syncEngine.enableNetwork();
205+
this.persistence.setNetworkEnabled(true);
206+
return this.remoteStore.enableNetwork();
206207
});
207208
}
208209

@@ -334,7 +335,8 @@ export class FirestoreClient {
334335
disableNetwork(): Promise<void> {
335336
this.verifyNotTerminated();
336337
return this.asyncQueue.enqueue(() => {
337-
return this.syncEngine.disableNetwork();
338+
this.persistence.setNetworkEnabled(true);
339+
return this.remoteStore.disableNetwork();
338340
});
339341
}
340342

packages/firestore/src/core/sync_engine.ts

+12-48
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
import { User } from '../auth/user';
1919
import {
20+
getNewDocumentChanges,
21+
getCachedTarget,
2022
ignoreIfPrimaryLeaseLoss,
2123
LocalStore,
22-
MultiTabLocalStore
24+
getCurrentlyActiveClients,
25+
lookupMutationDocuments,
26+
removeCachedMutationBatchMetadata
2327
} from '../local/local_store';
2428
import { LocalViewChanges } from '../local/local_view_changes';
2529
import { ReferenceSet } from '../local/reference_set';
@@ -225,10 +229,6 @@ export interface SyncEngine extends RemoteSyncer {
225229

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

228-
enableNetwork(): Promise<void>;
229-
230-
disableNetwork(): Promise<void>;
231-
232232
getRemoteKeysForTarget(targetId: TargetId): DocumentKeySet;
233233
}
234234

@@ -940,14 +940,6 @@ class SyncEngineImpl implements SyncEngine {
940940
}
941941
}
942942

943-
enableNetwork(): Promise<void> {
944-
return this.remoteStore.enableNetwork();
945-
}
946-
947-
disableNetwork(): Promise<void> {
948-
return this.remoteStore.disableNetwork();
949-
}
950-
951943
getRemoteKeysForTarget(targetId: TargetId): DocumentKeySet {
952944
const limboResolution = this.activeLimboResolutionsByTarget.get(targetId);
953945
if (limboResolution && limboResolution.receivedDocument) {
@@ -1016,38 +1008,10 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
10161008
// `isPrimary` is true.
10171009
private _isPrimaryClient: undefined | boolean = undefined;
10181010

1019-
constructor(
1020-
protected localStore: MultiTabLocalStore,
1021-
remoteStore: RemoteStore,
1022-
datastore: Datastore,
1023-
sharedClientState: SharedClientState,
1024-
currentUser: User,
1025-
maxConcurrentLimboResolutions: number
1026-
) {
1027-
super(
1028-
localStore,
1029-
remoteStore,
1030-
datastore,
1031-
sharedClientState,
1032-
currentUser,
1033-
maxConcurrentLimboResolutions
1034-
);
1035-
}
1036-
10371011
get isPrimaryClient(): boolean {
10381012
return this._isPrimaryClient === true;
10391013
}
10401014

1041-
enableNetwork(): Promise<void> {
1042-
this.localStore.setNetworkEnabled(true);
1043-
return super.enableNetwork();
1044-
}
1045-
1046-
disableNetwork(): Promise<void> {
1047-
this.localStore.setNetworkEnabled(false);
1048-
return super.disableNetwork();
1049-
}
1050-
10511015
/**
10521016
* Reconcile the list of synced documents in an existing view with those
10531017
* from persistence.
@@ -1097,7 +1061,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
10971061
error?: FirestoreError
10981062
): Promise<void> {
10991063
this.assertSubscribed('applyBatchState()');
1100-
const documents = await this.localStore.lookupMutationDocuments(batchId);
1064+
const documents = await lookupMutationDocuments(this.localStore, batchId);
11011065

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

12791243
getActiveClients(): Promise<ClientId[]> {
1280-
return this.localStore.getActiveClients();
1244+
return getCurrentlyActiveClients(this.localStore);
12811245
}
12821246

12831247
async applyTargetState(
@@ -1296,7 +1260,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
12961260
switch (state) {
12971261
case 'current':
12981262
case 'not-current': {
1299-
const changes = await this.localStore.getNewDocumentChanges();
1263+
const changes = await getNewDocumentChanges(this.localStore);
13001264
const synthesizedRemoteEvent = RemoteEvent.createSynthesizedRemoteEventForCurrentChange(
13011265
targetId,
13021266
state === 'current'
@@ -1336,7 +1300,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
13361300
continue;
13371301
}
13381302

1339-
const target = await this.localStore.getTarget(targetId);
1303+
const target = await getCachedTarget(this.localStore, targetId);
13401304
debugAssert(
13411305
!!target,
13421306
`Query data for active target ${targetId} not found`
@@ -1370,7 +1334,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
13701334
}
13711335

13721336
export function newMultiTabSyncEngine(
1373-
localStore: MultiTabLocalStore,
1337+
localStore: LocalStore,
13741338
remoteStore: RemoteStore,
13751339
datastore: Datastore,
13761340
sharedClientState: SharedClientState,

0 commit comments

Comments
 (0)