Skip to content

Commit 08708ee

Browse files
committed
Address comments
1 parent ff78ee9 commit 08708ee

File tree

2 files changed

+12
-108
lines changed

2 files changed

+12
-108
lines changed

packages/firestore/src/local/local_store.ts

Lines changed: 10 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export interface LocalStore {
153153
// change.
154154
handleUserChange(user: User): Promise<UserChangeResult>;
155155

156+
/* Accept locally generated Mutations and commit them to storage. */
156157
localWrite(mutations: Mutation[]): Promise<LocalWriteResult>;
157158

158159
/**
@@ -180,7 +181,9 @@ export interface LocalStore {
180181
rejectBatch(batchId: BatchId): Promise<MaybeDocumentMap>;
181182

182183
/**
183-
* Returns the largest (latest) batch id in mutation queue that is pending server response.
184+
* Returns the largest (latest) batch id in mutation queue that is pending
185+
* server response.
186+
*
184187
* Returns `BATCHID_UNKNOWN` if the queue is empty.
185188
*/
186189
getHighestUnacknowledgedBatchId(): Promise<BatchId>;
@@ -270,9 +273,9 @@ export interface LocalStore {
270273
* Implements `LocalStore` interface.
271274
*
272275
* Note: some field defined in this class might have public access level, but
273-
* the class is not exported so they are only accessible from this file. This is
274-
* useful to implement optional features (like bundles) in free functions, such
275-
* that they are tree-shakeable.
276+
* the class is not exported so they are only accessible from this module.
277+
* This is useful to implement optional features (like bundles) in free
278+
* functions, such that they are tree-shakeable.
276279
*/
277280
class LocalStoreImpl implements LocalStore {
278281
/**
@@ -347,19 +350,10 @@ class LocalStoreImpl implements LocalStore {
347350
this.queryEngine.setLocalDocumentsView(this.localDocuments);
348351
}
349352

350-
/** Starts the LocalStore. */
351353
start(): Promise<void> {
352354
return Promise.resolve();
353355
}
354356

355-
/**
356-
* Tells the LocalStore that the currently authenticated user has changed.
357-
*
358-
* In response the local store switches the mutation queue to the new user and
359-
* returns any resulting document changes.
360-
*/
361-
// PORTING NOTE: Android and iOS only return the documents affected by the
362-
// change.
363357
async handleUserChange(user: User): Promise<UserChangeResult> {
364358
let newMutationQueue = this.mutationQueue;
365359
let newLocalDocuments = this.localDocuments;
@@ -430,7 +424,6 @@ class LocalStoreImpl implements LocalStore {
430424
return result;
431425
}
432426

433-
/* Accept locally generated Mutations and commit them to storage. */
434427
localWrite(mutations: Mutation[]): Promise<LocalWriteResult> {
435428
const localWriteTime = Timestamp.now();
436429
const keys = mutations.reduce(
@@ -488,20 +481,6 @@ class LocalStoreImpl implements LocalStore {
488481
});
489482
}
490483

491-
/**
492-
* Acknowledge the given batch.
493-
*
494-
* On the happy path when a batch is acknowledged, the local store will
495-
*
496-
* + remove the batch from the mutation queue;
497-
* + apply the changes to the remote document cache;
498-
* + recalculate the latency compensated view implied by those changes (there
499-
* may be mutations in the queue that affect the documents but haven't been
500-
* acknowledged yet); and
501-
* + give the changed documents back the sync engine
502-
*
503-
* @returns The resulting (modified) documents.
504-
*/
505484
acknowledgeBatch(
506485
batchResult: MutationBatchResult
507486
): Promise<MaybeDocumentMap> {
@@ -525,12 +504,6 @@ class LocalStoreImpl implements LocalStore {
525504
);
526505
}
527506

528-
/**
529-
* Remove mutations from the MutationQueue for the specified batch;
530-
* LocalDocuments will be recalculated.
531-
*
532-
* @returns The resulting modified documents.
533-
*/
534507
rejectBatch(batchId: BatchId): Promise<MaybeDocumentMap> {
535508
return this.persistence.runTransaction(
536509
'Reject batch',
@@ -554,10 +527,6 @@ class LocalStoreImpl implements LocalStore {
554527
);
555528
}
556529

557-
/**
558-
* Returns the largest (latest) batch id in mutation queue that is pending server response.
559-
* Returns `BATCHID_UNKNOWN` if the queue is empty.
560-
*/
561530
getHighestUnacknowledgedBatchId(): Promise<BatchId> {
562531
return this.persistence.runTransaction(
563532
'Get highest unacknowledged batch id',
@@ -568,10 +537,6 @@ class LocalStoreImpl implements LocalStore {
568537
);
569538
}
570539

571-
/**
572-
* Returns the last consistent snapshot processed (used by the RemoteStore to
573-
* determine whether to buffer incoming snapshots from the backend).
574-
*/
575540
getLastRemoteSnapshotVersion(): Promise<SnapshotVersion> {
576541
return this.persistence.runTransaction(
577542
'Get last remote snapshot version',
@@ -580,14 +545,6 @@ class LocalStoreImpl implements LocalStore {
580545
);
581546
}
582547

583-
/**
584-
* Update the "ground-state" (remote) documents. We assume that the remote
585-
* event reflects any write batches that have been acknowledged or rejected
586-
* (i.e. we do not re-apply local mutations to updates from this event).
587-
*
588-
* LocalDocuments are re-calculated if there are remaining mutations in the
589-
* queue.
590-
*/
591548
applyRemoteEvent(remoteEvent: RemoteEvent): Promise<MaybeDocumentMap> {
592549
const remoteVersion = remoteEvent.snapshotVersion;
593550
let newTargetDataByTargetMap = this.targetDataByTarget;
@@ -801,9 +758,6 @@ class LocalStoreImpl implements LocalStore {
801758
return changes > 0;
802759
}
803760

804-
/**
805-
* Notify local store of the changed views to locally pin documents.
806-
*/
807761
async notifyLocalViewChanges(viewChanges: LocalViewChanges[]): Promise<void> {
808762
try {
809763
await this.persistence.runTransaction(
@@ -871,12 +825,6 @@ class LocalStoreImpl implements LocalStore {
871825
}
872826
}
873827

874-
/**
875-
* Gets the mutation batch after the passed in batchId in the mutation queue
876-
* or null if empty.
877-
* @param afterBatchId If provided, the batch to search after.
878-
* @returns The next mutation or null if there wasn't one.
879-
*/
880828
nextMutationBatch(afterBatchId?: BatchId): Promise<MutationBatch | null> {
881829
return this.persistence.runTransaction(
882830
'Get next mutation batch',
@@ -893,24 +841,12 @@ class LocalStoreImpl implements LocalStore {
893841
);
894842
}
895843

896-
/**
897-
* Read the current value of a Document with a given key or null if not
898-
* found - used for testing.
899-
*/
900844
readDocument(key: DocumentKey): Promise<MaybeDocument | null> {
901845
return this.persistence.runTransaction('read document', 'readonly', txn => {
902846
return this.localDocuments.getDocument(txn, key);
903847
});
904848
}
905849

906-
/**
907-
* Assigns the given target an internal ID so that its results can be pinned so
908-
* they don't get GC'd. A target must be allocated in the local store before
909-
* the store can be used to manage its view.
910-
*
911-
* Allocating an already allocated `Target` will return the existing `TargetData`
912-
* for that `Target`.
913-
*/
914850
allocateTarget(target: Target): Promise<TargetData> {
915851
return this.persistence
916852
.runTransaction('Allocate target', 'readwrite', txn => {
@@ -961,11 +897,6 @@ class LocalStoreImpl implements LocalStore {
961897
});
962898
}
963899

964-
/**
965-
* Returns the TargetData as seen by the LocalStore, including updates that may
966-
* have not yet been persisted to the TargetCache.
967-
*/
968-
// Visible for testing.
969900
getTargetData(
970901
transaction: PersistenceTransaction,
971902
target: Target
@@ -980,14 +911,6 @@ class LocalStoreImpl implements LocalStore {
980911
}
981912
}
982913

983-
/**
984-
* Unpin all the documents associated with the given target. If
985-
* `keepPersistedTargetData` is set to false and Eager GC enabled, the method
986-
* directly removes the associated target data from the target cache.
987-
*
988-
* Releasing a non-existing `Target` is a no-op.
989-
*/
990-
// PORTING NOTE: `keepPersistedTargetData` is multi-tab only.
991914
releaseTarget(
992915
targetId: number,
993916
keepPersistedTargetData: boolean
@@ -1016,14 +939,6 @@ class LocalStoreImpl implements LocalStore {
1016939
});
1017940
}
1018941

1019-
/**
1020-
* Runs the specified query against the local store and returns the results,
1021-
* potentially taking advantage of query data from previous executions (such
1022-
* as the set of remote keys).
1023-
*
1024-
* @param usePreviousResults Whether results from previous executions can
1025-
* be used to optimize this query execution.
1026-
*/
1027942
executeQuery(
1028943
query: Query,
1029944
usePreviousResults: boolean
@@ -1160,9 +1075,9 @@ export interface MultiTabLocalStore extends LocalStore {
11601075
* for MultiTabSyncEngine.
11611076
*
11621077
* Note: some field defined in this class might have public access level, but
1163-
* the class is not exported so they are only accessible from this file. This is
1164-
* useful to implement optional features (like bundles) in free functions, such
1165-
* that they are tree-shakeable.
1078+
* the class is not exported so they are only accessible from this module.
1079+
* This is useful to implement optional features (like bundles) in free
1080+
* functions, such that they are tree-shakeable.
11661081
*/
11671082
// PORTING NOTE: Web only.
11681083
class MultiTabLocalStoreImpl extends LocalStoreImpl
@@ -1188,7 +1103,6 @@ class MultiTabLocalStoreImpl extends LocalStoreImpl
11881103
return this.synchronizeLastDocumentChangeReadTime();
11891104
}
11901105

1191-
/** Returns the local view of the documents affected by a mutation batch. */
11921106
lookupMutationDocuments(batchId: BatchId): Promise<MaybeDocumentMap | null> {
11931107
return this.persistence.runTransaction(
11941108
'Lookup mutation documents',
@@ -1240,12 +1154,6 @@ class MultiTabLocalStoreImpl extends LocalStoreImpl
12401154
}
12411155
}
12421156

1243-
/**
1244-
* Returns the set of documents that have been updated since the last call.
1245-
* If this is the first call, returns the set of changes since client
1246-
* initialization. Further invocations will return document changes since
1247-
* the point of rejection.
1248-
*/
12491157
getNewDocumentChanges(): Promise<MaybeDocumentMap> {
12501158
return this.persistence
12511159
.runTransaction('Get new document changes', 'readonly', txn =>
@@ -1260,11 +1168,6 @@ class MultiTabLocalStoreImpl extends LocalStoreImpl
12601168
});
12611169
}
12621170

1263-
/**
1264-
* Reads the newest document change from persistence and forwards the internal
1265-
* synchronization marker so that calls to `getNewDocumentChanges()`
1266-
* only return changes that happened after client initialization.
1267-
*/
12681171
async synchronizeLastDocumentChangeReadTime(): Promise<void> {
12691172
this.lastDocumentChangeReadTime = await this.persistence.runTransaction(
12701173
'Synchronize last document change read time',

packages/firestore/test/unit/local/local_store.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import { IndexedDbPersistence } from '../../../src/local/indexeddb_persistence';
3030
import {
3131
LocalStore,
3232
LocalWriteResult,
33-
newLocalStore, newMultiTabLocalStore
33+
newLocalStore,
34+
newMultiTabLocalStore
3435
} from '../../../src/local/local_store';
3536
import { LocalViewChanges } from '../../../src/local/local_view_changes';
3637
import { Persistence } from '../../../src/local/persistence';

0 commit comments

Comments
 (0)