Skip to content

Commit 80c870e

Browse files
authored
Merge 5ed48fa into 9fb82cb
2 parents 9fb82cb + 5ed48fa commit 80c870e

21 files changed

+1401
-293
lines changed

packages/firestore/src/local/document_overlay_cache.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { DocumentKeySet } from '../model/collections';
18+
import {
19+
DocumentKeySet,
20+
DocumentKeyToMutationMap,
21+
DocumentKeyToOverlayMap
22+
} from '../model/collections';
1923
import { DocumentKey } from '../model/document_key';
20-
import { Mutation } from '../model/mutation';
2124
import { Overlay } from '../model/overlay';
2225
import { ResourcePath } from '../model/path';
2326

@@ -51,7 +54,7 @@ export interface DocumentOverlayCache {
5154
saveOverlays(
5255
transaction: PersistenceTransaction,
5356
largestBatchId: number,
54-
overlays: Map<DocumentKey, Mutation>
57+
overlays: DocumentKeyToMutationMap
5558
): PersistencePromise<void>;
5659

5760
/** Removes overlays for the given document keys and batch ID. */
@@ -74,7 +77,7 @@ export interface DocumentOverlayCache {
7477
transaction: PersistenceTransaction,
7578
collection: ResourcePath,
7679
sinceBatchId: number
77-
): PersistencePromise<Map<DocumentKey, Overlay>>;
80+
): PersistencePromise<DocumentKeyToOverlayMap>;
7881

7982
/**
8083
* Returns `count` overlays with a batch ID higher than `sinceBatchId` for the
@@ -95,5 +98,5 @@ export interface DocumentOverlayCache {
9598
collectionGroup: string,
9699
sinceBatchId: number,
97100
count: number
98-
): PersistencePromise<Map<DocumentKey, Overlay>>;
101+
): PersistencePromise<DocumentKeyToOverlayMap>;
99102
}

packages/firestore/src/local/indexeddb_document_overlay_cache.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616
*/
1717

1818
import { User } from '../auth/user';
19-
import { DocumentKeySet } from '../model/collections';
19+
import {
20+
DocumentKeySet,
21+
DocumentKeyToMutationMap,
22+
DocumentKeyToOverlayMap,
23+
newDocumentKeyToOverlayMap
24+
} from '../model/collections';
2025
import { DocumentKey } from '../model/document_key';
21-
import { Mutation } from '../model/mutation';
2226
import { Overlay } from '../model/overlay';
2327
import { ResourcePath } from '../model/path';
2428

@@ -74,10 +78,10 @@ export class IndexedDbDocumentOverlayCache implements DocumentOverlayCache {
7478
saveOverlays(
7579
transaction: PersistenceTransaction,
7680
largestBatchId: number,
77-
overlays: Map<DocumentKey, Mutation>
81+
overlays: DocumentKeyToMutationMap
7882
): PersistencePromise<void> {
7983
const promises: Array<PersistencePromise<void>> = [];
80-
overlays.forEach(mutation => {
84+
overlays.forEach((_, mutation) => {
8185
const overlay = new Overlay(largestBatchId, mutation);
8286
promises.push(this.saveOverlay(transaction, overlay));
8387
});
@@ -118,8 +122,8 @@ export class IndexedDbDocumentOverlayCache implements DocumentOverlayCache {
118122
transaction: PersistenceTransaction,
119123
collection: ResourcePath,
120124
sinceBatchId: number
121-
): PersistencePromise<Map<DocumentKey, Overlay>> {
122-
const result = new Map<DocumentKey, Overlay>();
125+
): PersistencePromise<DocumentKeyToOverlayMap> {
126+
const result = newDocumentKeyToOverlayMap();
123127
const collectionPath = encodeResourcePath(collection);
124128
// We want batch IDs larger than `sinceBatchId`, and so the lower bound
125129
// is not inclusive.
@@ -144,8 +148,8 @@ export class IndexedDbDocumentOverlayCache implements DocumentOverlayCache {
144148
collectionGroup: string,
145149
sinceBatchId: number,
146150
count: number
147-
): PersistencePromise<Map<DocumentKey, Overlay>> {
148-
const result = new Map<DocumentKey, Overlay>();
151+
): PersistencePromise<DocumentKeyToOverlayMap> {
152+
const result = newDocumentKeyToOverlayMap();
149153
let currentBatchId: number | undefined = undefined;
150154
// We want batch IDs larger than `sinceBatchId`, and so the lower bound
151155
// is not inclusive.
@@ -167,7 +171,7 @@ export class IndexedDbDocumentOverlayCache implements DocumentOverlayCache {
167171
// `count` if there are more overlays from the `currentBatchId`.
168172
const overlay = fromDbDocumentOverlay(this.serializer, dbOverlay);
169173
if (
170-
result.size < count ||
174+
result.size() < count ||
171175
overlay.largestBatchId === currentBatchId
172176
) {
173177
result.set(overlay.getKey(), overlay);

0 commit comments

Comments
 (0)