@@ -25,14 +25,13 @@ import {
25
25
import { SnapshotVersion } from '../core/snapshot_version' ;
26
26
import {
27
27
DocumentKeySet ,
28
- documentKeySet ,
29
28
DocumentMap ,
30
29
documentMap ,
31
30
MutableDocumentMap
32
31
} from '../model/collections' ;
33
32
import { Document , MutableDocument } from '../model/document' ;
34
33
import { DocumentKey } from '../model/document_key' ;
35
- import { mutationApplyToLocalView , PatchMutation } from '../model/mutation' ;
34
+ import { mutationApplyToLocalView } from '../model/mutation' ;
36
35
import { MutationBatch } from '../model/mutation_batch' ;
37
36
import { ResourcePath } from '../model/path' ;
38
37
import { debugAssert } from '../util/assert' ;
@@ -217,51 +216,31 @@ export class LocalDocumentsView {
217
216
) : PersistencePromise < DocumentMap > {
218
217
// Query the remote documents and overlay mutations.
219
218
let results : MutableDocumentMap ;
220
- let mutationBatches : MutationBatch [ ] ;
221
219
return this . remoteDocumentCache
222
- . getDocumentsMatchingQuery ( transaction , query , sinceReadTime )
220
+ . getAll ( transaction , query . path , sinceReadTime )
223
221
. next ( queryResults => {
224
222
results = queryResults ;
225
223
return this . mutationQueue . getAllMutationBatchesAffectingQuery (
226
224
transaction ,
227
225
query
228
226
) ;
229
227
} )
230
- . next ( matchingMutationBatches => {
231
- mutationBatches = matchingMutationBatches ;
232
- // It is possible that a PatchMutation can make a document match a query, even if
233
- // the version in the RemoteDocumentCache is not a match yet (waiting for server
234
- // to ack). To handle this, we find all document keys affected by the PatchMutations
235
- // that are not in `result` yet, and back fill them via `remoteDocumentCache.getEntries`,
236
- // otherwise those `PatchMutations` will be ignored because no base document can be found,
237
- // and lead to missing result for the query.
238
- return this . addMissingBaseDocuments (
239
- transaction ,
240
- mutationBatches ,
241
- results
242
- ) . next ( mergedDocuments => {
243
- results = mergedDocuments ;
244
-
245
- for ( const batch of mutationBatches ) {
246
- for ( const mutation of batch . mutations ) {
247
- const key = mutation . key ;
248
- let document = results . get ( key ) ;
249
- if ( document == null ) {
250
- // Create invalid document to apply mutations on top of
251
- document = MutableDocument . newInvalidDocument ( key ) ;
252
- results = results . insert ( key , document ) ;
253
- }
254
- mutationApplyToLocalView (
255
- mutation ,
256
- document ,
257
- batch . localWriteTime
258
- ) ;
259
- if ( ! document . isFoundDocument ( ) ) {
260
- results = results . remove ( key ) ;
261
- }
228
+ . next ( mutationBatches => {
229
+ for ( const batch of mutationBatches ) {
230
+ for ( const mutation of batch . mutations ) {
231
+ const key = mutation . key ;
232
+ let document = results . get ( key ) ;
233
+ if ( document == null ) {
234
+ // Create invalid document to apply mutations on top of
235
+ document = MutableDocument . newInvalidDocument ( key ) ;
236
+ results = results . insert ( key , document ) ;
237
+ }
238
+ mutationApplyToLocalView ( mutation , document , batch . localWriteTime ) ;
239
+ if ( ! document . isFoundDocument ( ) ) {
240
+ results = results . remove ( key ) ;
262
241
}
263
242
}
264
- } ) ;
243
+ }
265
244
} )
266
245
. next ( ( ) => {
267
246
// Finally, filter out any documents that don't actually match
@@ -275,35 +254,4 @@ export class LocalDocumentsView {
275
254
return results as DocumentMap ;
276
255
} ) ;
277
256
}
278
-
279
- private addMissingBaseDocuments (
280
- transaction : PersistenceTransaction ,
281
- matchingMutationBatches : MutationBatch [ ] ,
282
- existingDocuments : MutableDocumentMap
283
- ) : PersistencePromise < MutableDocumentMap > {
284
- let missingBaseDocEntriesForPatching = documentKeySet ( ) ;
285
- for ( const batch of matchingMutationBatches ) {
286
- for ( const mutation of batch . mutations ) {
287
- if (
288
- mutation instanceof PatchMutation &&
289
- existingDocuments . get ( mutation . key ) === null
290
- ) {
291
- missingBaseDocEntriesForPatching =
292
- missingBaseDocEntriesForPatching . add ( mutation . key ) ;
293
- }
294
- }
295
- }
296
-
297
- let mergedDocuments = existingDocuments ;
298
- return this . remoteDocumentCache
299
- . getEntries ( transaction , missingBaseDocEntriesForPatching )
300
- . next ( missingBaseDocs => {
301
- missingBaseDocs . forEach ( ( key , doc ) => {
302
- if ( doc . isFoundDocument ( ) ) {
303
- mergedDocuments = mergedDocuments . insert ( key , doc ) ;
304
- }
305
- } ) ;
306
- return mergedDocuments ;
307
- } ) ;
308
- }
309
257
}
0 commit comments