Skip to content

Commit 529a627

Browse files
Tree-shake LocalStore
1 parent 5b7d812 commit 529a627

File tree

4 files changed

+154
-191
lines changed

4 files changed

+154
-191
lines changed

packages/firestore/src/core/component_provider.ts

Lines changed: 2 additions & 11 deletions
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,
@@ -125,7 +124,6 @@ export class MemoryComponentProvider implements ComponentProvider {
125124
);
126125
this.remoteStore.syncEngine = this.syncEngine;
127126

128-
await this.localStore.start();
129127
await this.sharedClientState.start();
130128
await this.remoteStore.start();
131129

@@ -281,7 +279,6 @@ export class IndexedDbComponentProvider extends MemoryComponentProvider {
281279
* `synchronizeTabs` will be enabled.
282280
*/
283281
export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvider {
284-
localStore!: MultiTabLocalStore;
285282
syncEngine!: MultiTabSyncEngine;
286283

287284
async initialize(cfg: ComponentConfiguration): Promise<void> {
@@ -301,14 +298,8 @@ export class MultiTabIndexedDbComponentProvider extends IndexedDbComponentProvid
301298
}
302299
}
303300
});
304-
}
305301

306-
createLocalStore(cfg: ComponentConfiguration): LocalStore {
307-
return newMultiTabLocalStore(
308-
this.persistence,
309-
new IndexFreeQueryEngine(),
310-
cfg.initialUser
311-
);
302+
await synchronizeLastDocumentChangeReadTime(this.localStore);
312303
}
313304

314305
createSyncEngine(cfg: ComponentConfiguration): SyncEngine {

packages/firestore/src/core/sync_engine.ts

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717

1818
import { User } from '../auth/user';
1919
import {
20+
getNewDocumentChanges,
21+
getTarget,
2022
ignoreIfPrimaryLeaseLoss,
2123
LocalStore,
22-
MultiTabLocalStore
24+
localStoreGetActiveClients,
25+
lookupMutationDocuments,
26+
removeCachedMutationBatchMetadata,
27+
setNetworkEnabled
2328
} from '../local/local_store';
2429
import { LocalViewChanges } from '../local/local_view_changes';
2530
import { ReferenceSet } from '../local/reference_set';
@@ -1016,35 +1021,17 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
10161021
// `isPrimary` is true.
10171022
private _isPrimaryClient: undefined | boolean = undefined;
10181023

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-
10371024
get isPrimaryClient(): boolean {
10381025
return this._isPrimaryClient === true;
10391026
}
10401027

10411028
enableNetwork(): Promise<void> {
1042-
this.localStore.setNetworkEnabled(true);
1029+
setNetworkEnabled(this.localStore, true);
10431030
return super.enableNetwork();
10441031
}
10451032

10461033
disableNetwork(): Promise<void> {
1047-
this.localStore.setNetworkEnabled(false);
1034+
setNetworkEnabled(this.localStore, false);
10481035
return super.disableNetwork();
10491036
}
10501037

@@ -1097,7 +1084,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
10971084
error?: FirestoreError
10981085
): Promise<void> {
10991086
this.assertSubscribed('applyBatchState()');
1100-
const documents = await this.localStore.lookupMutationDocuments(batchId);
1087+
const documents = await lookupMutationDocuments(this.localStore, batchId);
11011088

11021089
if (documents === null) {
11031090
// A throttled tab may not have seen the mutation before it was completed
@@ -1120,7 +1107,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
11201107
// NOTE: Both these methods are no-ops for batches that originated from
11211108
// other clients.
11221109
this.processUserCallback(batchId, error ? error : null);
1123-
this.localStore.removeCachedMutationBatchMetadata(batchId);
1110+
removeCachedMutationBatchMetadata(this.localStore, batchId);
11241111
} else {
11251112
fail(`Unknown batchState: ${batchState}`);
11261113
}
@@ -1236,7 +1223,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
12361223
);
12371224
// For queries that never executed on this client, we need to
12381225
// allocate the target in LocalStore and initialize a new View.
1239-
const target = await this.localStore.getTarget(targetId);
1226+
const target = await getTarget(this.localStore, targetId);
12401227
debugAssert(!!target, `Target for id ${targetId} not found`);
12411228
targetData = await this.localStore.allocateTarget(target);
12421229
await this.initializeViewAndComputeSnapshot(
@@ -1277,7 +1264,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
12771264
}
12781265

12791266
getActiveClients(): Promise<ClientId[]> {
1280-
return this.localStore.getActiveClients();
1267+
return localStoreGetActiveClients(this.localStore);
12811268
}
12821269

12831270
async applyTargetState(
@@ -1296,7 +1283,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
12961283
switch (state) {
12971284
case 'current':
12981285
case 'not-current': {
1299-
const changes = await this.localStore.getNewDocumentChanges();
1286+
const changes = await getNewDocumentChanges(this.localStore);
13001287
const synthesizedRemoteEvent = RemoteEvent.createSynthesizedRemoteEventForCurrentChange(
13011288
targetId,
13021289
state === 'current'
@@ -1336,7 +1323,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
13361323
continue;
13371324
}
13381325

1339-
const target = await this.localStore.getTarget(targetId);
1326+
const target = await getTarget(this.localStore, targetId);
13401327
debugAssert(
13411328
!!target,
13421329
`Query data for active target ${targetId} not found`
@@ -1370,7 +1357,7 @@ class MultiTabSyncEngineImpl extends SyncEngineImpl {
13701357
}
13711358

13721359
export function newMultiTabSyncEngine(
1373-
localStore: MultiTabLocalStore,
1360+
localStore: LocalStore,
13741361
remoteStore: RemoteStore,
13751362
datastore: Datastore,
13761363
sharedClientState: SharedClientState,

0 commit comments

Comments
 (0)