Skip to content

Commit b63ea07

Browse files
committed
Address comments.
1 parent 92d5341 commit b63ea07

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

packages/firestore/src/local/document_overlay_cache.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface DocumentOverlayCache {
5353
overlays: Map<DocumentKey, Mutation>
5454
): PersistencePromise<void>;
5555

56-
/** Removes the overlay whose largest-batch-id equals the given Id. */
56+
/** Removes the overlay whose largest-batch-id equals the given ID. */
5757
removeOverlaysForBatchId(
5858
transaction: PersistenceTransaction,
5959
batchId: number
@@ -62,9 +62,9 @@ export interface DocumentOverlayCache {
6262
/**
6363
* Returns all saved overlays for the given collection.
6464
*
65-
* @param transaction The persistence transaction to use for this operation.
66-
* @param collection The collection path to get the overlays for.
67-
* @param sinceBatchId The minimum batch ID to filter by (exclusive).
65+
* @param transaction - The persistence transaction to use for this operation.
66+
* @param collection - The collection path to get the overlays for.
67+
* @param sinceBatchId - The minimum batch ID to filter by (exclusive).
6868
* Only overlays that contain a change past `sinceBatchId` are returned.
6969
* @returns Mapping of each document key in the collection to its overlay.
7070
*/
@@ -80,11 +80,11 @@ export interface DocumentOverlayCache {
8080
* always returns all overlays for a batch even if the last batch contains
8181
* more documents than the remaining limit.
8282
*
83-
* @param transaction The persistence transaction used for this operation.
84-
* @param collectionGroup The collection group to get the overlays for.
85-
* @param sinceBatchId The minimum batch ID to filter by (exclusive).
83+
* @param transaction - The persistence transaction used for this operation.
84+
* @param collectionGroup - The collection group to get the overlays for.
85+
* @param sinceBatchId - The minimum batch ID to filter by (exclusive).
8686
* Only overlays that contain a change past `sinceBatchId` are returned.
87-
* @param count The number of overlays to return. Can be exceeded if the last
87+
* @param count - The number of overlays to return. Can be exceeded if the last
8888
* batch contains more entries.
8989
* @return Mapping of each document key in the collection group to its overlay.
9090
*/

packages/firestore/src/local/indexeddb_document_overlay_cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { PersistenceTransaction } from './persistence_transaction';
3636
import { SimpleDbStore } from './simple_db';
3737

3838
/**
39-
* An in-memory implementation of DocumentOverlayCache.
39+
* Implementation of DocumentOverlayCache using IndexedDb.
4040
*/
4141
export class IndexedDbDocumentOverlayCache implements DocumentOverlayCache {
4242
/**

packages/firestore/src/local/local_serializer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,10 @@ export function toDbDocumentOverlay(
426426
);
427427
}
428428

429-
/** Returns the DbDocumentOverlayKey corresponding to the given user and document key. */
429+
/**
430+
* Returns the DbDocumentOverlayKey corresponding to the given user and
431+
* document key.
432+
*/
430433
export function toDbDocumentOverlayKey(
431434
userId: string,
432435
docKey: DocumentKey

packages/firestore/src/local/memory_document_overlay_cache.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ export class MemoryDocumentOverlayCache implements DocumentOverlayCache {
111111
const entry = iter.getNext();
112112
const overlay = entry.value;
113113
const key = overlay.getKey();
114-
// TODO(overlays): We should consider using the IndexManager to get the list of collection paths first.
115114
if (key.getCollectionGroup() !== collectionGroup) {
116115
continue;
117116
}
@@ -162,9 +161,11 @@ export class MemoryDocumentOverlayCache implements DocumentOverlayCache {
162161
);
163162

164163
// Create the association of this overlay to the given largestBatchId.
165-
if (this.overlayByBatchId.get(largestBatchId) === undefined) {
166-
this.overlayByBatchId.set(largestBatchId, new Set<DocumentKey>());
164+
let batch = this.overlayByBatchId.get(largestBatchId);
165+
if (batch === undefined) {
166+
batch = new Set<DocumentKey>();
167+
this.overlayByBatchId.set(largestBatchId, batch);
167168
}
168-
this.overlayByBatchId.get(largestBatchId)!.add(mutation.key);
169+
batch.add(mutation.key);
169170
}
170171
}

packages/firestore/src/model/overlay.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
import { DocumentKey } from './document_key';
1919
import { Mutation } from './mutation';
2020

21+
/**
22+
* Representation of an overlay computed by Firestore.
23+
*
24+
* Holds information about a mutation and the largest batch id in Firestore when
25+
* the mutation was created.
26+
*/
2127
export class Overlay {
2228
constructor(readonly largestBatchId: number, readonly mutation: Mutation) {}
2329

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import { expect } from 'chai';
1919

2020
import { DatabaseId } from '../../../src/core/database_info';
21-
import { decodeResourcePath } from '../../../src/local/encoded_resource_path';
21+
import { encodeResourcePath } from '../../../src/local/encoded_resource_path';
2222
import { DbMutationBatch } from '../../../src/local/indexeddb_schema';
2323
import {
2424
fromDbDocumentOverlay,
@@ -31,9 +31,9 @@ import {
3131
SetMutation
3232
} from '../../../src/model/mutation';
3333
import { Overlay } from '../../../src/model/overlay';
34+
import { ResourcePath } from '../../../src/model/path';
3435
import { Write } from '../../../src/protos/firestore_proto_api';
3536
import {
36-
fromMutation,
3737
JsonProtoSerializer,
3838
toDocumentMask,
3939
toMutation,
@@ -196,16 +196,16 @@ describe('Local Serializer', () => {
196196
const overlay = new Overlay(2, m);
197197

198198
const serialized = toDbDocumentOverlay(localSerializer, userId, overlay);
199-
expect(serialized.userId).to.equal(userId);
200-
expect(serialized.largestBatchId).to.equal(2);
201-
expect(serialized.documentId).to.equal('doc2');
202-
expect(
203-
decodeResourcePath(serialized.collectionPath).canonicalString()
204-
).to.equal('coll1/doc1/coll2');
205-
expect(serialized.collectionGroup).to.equal('coll2');
206-
expect(
207-
mutationEquals(fromMutation(s, serialized.overlayMutation), m)
208-
).to.equal(true);
199+
expect(serialized).to.deep.equal({
200+
userId,
201+
collectionPath: encodeResourcePath(
202+
ResourcePath.fromString('coll1/doc1/coll2')
203+
),
204+
documentId: 'doc2',
205+
collectionGroup: 'coll2',
206+
largestBatchId: 2,
207+
overlayMutation: toMutation(localSerializer.remoteSerializer, m)
208+
});
209209

210210
const roundTripped = fromDbDocumentOverlay(localSerializer, serialized);
211211
expect(roundTripped.largestBatchId).to.equal(overlay.largestBatchId);

0 commit comments

Comments
 (0)