@@ -24,27 +24,28 @@ import {
24
24
} from '../core/query' ;
25
25
import { Timestamp } from '../lite-api/timestamp' ;
26
26
import {
27
- documentKeySet ,
28
27
DocumentKeySet ,
28
+ DocumentKeyToOverlayMap ,
29
29
DocumentMap ,
30
- documentMap ,
31
- mutableDocumentMap ,
32
- MutableDocumentMap
30
+ MutableDocumentMap ,
31
+ newDocumentKeyMap ,
32
+ newDocumentKeyToMutationMap ,
33
+ newDocumentKeyToOverlayMap
33
34
} from '../model/collections' ;
34
35
import { Document , MutableDocument } from '../model/document' ;
35
36
import { DocumentKey } from '../model/document_key' ;
36
37
import { IndexOffset } from '../model/field_index' ;
37
38
import { FieldMask } from '../model/field_mask' ;
38
39
import {
39
40
calculateOverlayMutation ,
40
- Mutation ,
41
41
mutationApplyToLocalView ,
42
42
PatchMutation
43
43
} from '../model/mutation' ;
44
44
import { Overlay } from '../model/overlay' ;
45
45
import { ResourcePath } from '../model/path' ;
46
46
import { debugAssert } from '../util/assert' ;
47
47
import { SortedMap } from '../util/sorted_map' ;
48
+ import { SortedSet } from '../util/sorted_set' ;
48
49
49
50
import { DocumentOverlayCache } from './document_overlay_cache' ;
50
51
import { IndexManager } from './index_manager' ;
@@ -110,9 +111,11 @@ export class LocalDocumentsView {
110
111
return this . remoteDocumentCache
111
112
. getEntries ( transaction , keys )
112
113
. next ( docs =>
113
- this . getLocalViewOfDocuments ( transaction , docs , documentKeySet ( ) ) . next (
114
- ( ) => docs as DocumentMap
115
- )
114
+ this . getLocalViewOfDocuments (
115
+ transaction ,
116
+ docs ,
117
+ new SortedSet ( DocumentKey . comparator )
118
+ ) . next ( ( ) => docs as DocumentMap )
116
119
) ;
117
120
}
118
121
@@ -134,7 +137,7 @@ export class LocalDocumentsView {
134
137
return this . computeViews (
135
138
transaction ,
136
139
docs ,
137
- new Map < DocumentKey , Overlay > ( ) ,
140
+ newDocumentKeyToOverlayMap ( ) ,
138
141
existenceStateChanged
139
142
) ;
140
143
}
@@ -146,11 +149,13 @@ export class LocalDocumentsView {
146
149
computeViews (
147
150
transaction : PersistenceTransaction ,
148
151
docs : MutableDocumentMap ,
149
- memoizedOverlays : Map < DocumentKey , Overlay > ,
152
+ memoizedOverlays : DocumentKeyToOverlayMap ,
150
153
existenceStateChanged : DocumentKeySet
151
154
) : PersistencePromise < DocumentMap > {
152
- let results = documentMap ( ) ;
153
- let recalculateDocuments = mutableDocumentMap ( ) ;
155
+ let results = new SortedMap < DocumentKey , Document > ( DocumentKey . comparator ) ;
156
+ let recalculateDocuments = new SortedMap < DocumentKey , MutableDocument > (
157
+ DocumentKey . comparator
158
+ ) ;
154
159
const promises : Array < PersistencePromise < void > > = [ ] ;
155
160
docs . forEach ( ( _ , doc ) => {
156
161
const overlayPromise = memoizedOverlays . has ( doc . key )
@@ -199,12 +204,12 @@ export class LocalDocumentsView {
199
204
transaction : PersistenceTransaction ,
200
205
docs : MutableDocumentMap
201
206
) : PersistencePromise < void > {
202
- const masks = new Map < DocumentKey , FieldMask | null > ( ) ;
207
+ const masks = newDocumentKeyMap < FieldMask | null > ( ) ;
203
208
// A reverse lookup map from batch id to the documents within that batch.
204
- let documentsByBatchId = new SortedMap < number , Set < DocumentKey > > (
209
+ let documentsByBatchId = new SortedMap < number , DocumentKeySet > (
205
210
( key1 : number , key2 : number ) => key1 - key2
206
211
) ;
207
- const processed = new Set < DocumentKey > ( ) ;
212
+ let processed = new SortedSet ( DocumentKey . comparator ) ;
208
213
return this . mutationQueue
209
214
. getAllMutationBatchesAffectingDocumentKeys ( transaction , docs )
210
215
. next ( batches => {
@@ -218,10 +223,11 @@ export class LocalDocumentsView {
218
223
if ( documentsByBatchId . get ( batch . batchId ) === null ) {
219
224
documentsByBatchId = documentsByBatchId . insert (
220
225
batch . batchId ,
221
- new Set < DocumentKey > ( )
226
+ new SortedSet ( DocumentKey . comparator )
222
227
) ;
223
228
}
224
- documentsByBatchId . get ( batch . batchId ) ! . add ( key ) ;
229
+ const newSet = documentsByBatchId . get ( batch . batchId ) ! . add ( key ) ;
230
+ documentsByBatchId . insert ( batch . batchId , newSet ) ;
225
231
} ) ;
226
232
} ) ;
227
233
} )
@@ -234,7 +240,7 @@ export class LocalDocumentsView {
234
240
const entry = iter . getNext ( ) ;
235
241
const batchId = entry . key ;
236
242
const keys = entry . value ;
237
- const overlays = new Map < DocumentKey , Mutation > ( ) ;
243
+ const overlays = newDocumentKeyToMutationMap ( ) ;
238
244
keys . forEach ( key => {
239
245
if ( ! processed . has ( key ) ) {
240
246
// TODO: Should we change `overlays` type to Map<DK, Mutation|null>
@@ -246,7 +252,7 @@ export class LocalDocumentsView {
246
252
if ( overlayMutation !== null ) {
247
253
overlays . set ( key , overlayMutation ) ;
248
254
}
249
- processed . add ( key ) ;
255
+ processed = processed . add ( key ) ;
250
256
}
251
257
} ) ;
252
258
promises . push (
@@ -313,7 +319,9 @@ export class LocalDocumentsView {
313
319
// Just do a simple document lookup.
314
320
return this . getDocument ( transaction , new DocumentKey ( docPath ) ) . next (
315
321
document => {
316
- let result = documentMap ( ) ;
322
+ let result = new SortedMap < DocumentKey , Document > (
323
+ DocumentKey . comparator
324
+ ) ;
317
325
if ( document . isFoundDocument ( ) ) {
318
326
result = result . insert ( document . key , document ) ;
319
327
}
@@ -332,7 +340,7 @@ export class LocalDocumentsView {
332
340
'Currently we only support collection group queries at the root.'
333
341
) ;
334
342
const collectionId = query . collectionGroup ! ;
335
- let results = documentMap ( ) ;
343
+ let results = new SortedMap < DocumentKey , Document > ( DocumentKey . comparator ) ;
336
344
return this . indexManager
337
345
. getCollectionParents ( transaction , collectionId )
338
346
. next ( parents => {
@@ -376,7 +384,7 @@ export class LocalDocumentsView {
376
384
. next ( overlays => {
377
385
// As documents might match the query because of their overlay we need to
378
386
// include documents for all overlays in the initial document set.
379
- overlays . forEach ( overlay => {
387
+ overlays . forEach ( ( _ , overlay ) => {
380
388
const key = overlay . getKey ( ) ;
381
389
if ( remoteDocuments . get ( key ) === null ) {
382
390
remoteDocuments = remoteDocuments . insert (
@@ -387,7 +395,9 @@ export class LocalDocumentsView {
387
395
} ) ;
388
396
389
397
// Apply the overlays and match against the query.
390
- let results = documentMap ( ) ;
398
+ let results = new SortedMap < DocumentKey , Document > (
399
+ DocumentKey . comparator
400
+ ) ;
391
401
remoteDocuments . forEach ( ( key , document ) => {
392
402
const overlay = overlays . get ( key ) ;
393
403
if ( overlay !== undefined ) {
0 commit comments