@@ -29,7 +29,10 @@ import {
29
29
} from '../model/collections' ;
30
30
import { Document , MaybeDocument , NoDocument } from '../model/document' ;
31
31
import { DocumentKey } from '../model/document_key' ;
32
+ import { ResourcePath } from '../model/path' ;
33
+ import { primitiveComparator } from '../util/misc' ;
32
34
import { SortedMap } from '../util/sorted_map' ;
35
+ import { SortedSet } from '../util/sorted_set' ;
33
36
34
37
import { SnapshotVersion } from '../core/snapshot_version' ;
35
38
import { assert , fail } from '../util/assert' ;
@@ -71,12 +74,7 @@ export class IndexedDbRemoteDocumentCache implements RemoteDocumentCache {
71
74
doc : DbRemoteDocument
72
75
) : PersistencePromise < void > {
73
76
const documentStore = remoteDocumentsStore ( transaction ) ;
74
- return documentStore . put ( dbKey ( key ) , doc ) . next ( ( ) => {
75
- this . indexManager . addToCollectionParentIndex (
76
- transaction ,
77
- key . path . popLast ( )
78
- ) ;
79
- } ) ;
77
+ return documentStore . put ( dbKey ( key ) , doc ) ;
80
78
}
81
79
82
80
/**
@@ -449,6 +447,10 @@ export class IndexedDbRemoteDocumentCache implements RemoteDocumentCache {
449
447
450
448
let sizeDelta = 0 ;
451
449
450
+ let collectionParents = new SortedSet < ResourcePath > ( ( l , r ) =>
451
+ primitiveComparator ( l . canonicalString ( ) , r . canonicalString ( ) )
452
+ ) ;
453
+
452
454
this . changes . forEach ( ( key , maybeDocument ) => {
453
455
const previousSize = this . documentSizes . get ( key ) ;
454
456
assert (
@@ -464,6 +466,8 @@ export class IndexedDbRemoteDocumentCache implements RemoteDocumentCache {
464
466
maybeDocument ,
465
467
this . readTime
466
468
) ;
469
+ collectionParents = collectionParents . add ( key . path . popLast ( ) ) ;
470
+
467
471
const size = dbDocumentSize ( doc ) ;
468
472
sizeDelta += size - previousSize ! ;
469
473
promises . push ( this . documentCache . addEntry ( transaction , key , doc ) ) ;
@@ -487,6 +491,15 @@ export class IndexedDbRemoteDocumentCache implements RemoteDocumentCache {
487
491
}
488
492
} ) ;
489
493
494
+ collectionParents . forEach ( parent => {
495
+ promises . push (
496
+ this . documentCache . indexManager . addToCollectionParentIndex (
497
+ transaction ,
498
+ parent
499
+ )
500
+ ) ;
501
+ } ) ;
502
+
490
503
promises . push ( this . documentCache . updateMetadata ( transaction , sizeDelta ) ) ;
491
504
492
505
return PersistencePromise . waitFor ( promises ) ;
0 commit comments