@@ -74,6 +74,8 @@ import {
7474 DbGlobalsStore ,
7575 DbIndexConfigurationCollectionGroupIndex ,
7676 DbIndexConfigurationCollectionGroupIndexPath ,
77+ DbRemoteDocumentCollectionIndex ,
78+ DbRemoteDocumentCollectionIndexPath ,
7779 DbIndexConfigurationKeyPath ,
7880 DbIndexConfigurationStore ,
7981 DbIndexEntryDocumentKeyIndex ,
@@ -296,26 +298,15 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
296298 }
297299
298300 if ( fromVersion < 19 && toVersion >= 19 ) {
299- p = p . next ( ( ) => this . backfillDocumentType ( simpleDbTransaction ) ) ;
301+ p = p . next ( ( ) => {
302+ createRemoteDocumentStoreDocumentTypeIndex ( txn ) ;
303+ return backfillRemoteDocumentStoreDocumentType ( simpleDbTransaction ) ;
304+ } ) ;
300305 }
301306
302307 return p ;
303308 }
304309
305- private backfillDocumentType (
306- txn : SimpleDbTransaction
307- ) : PersistencePromise < void > {
308- const remoteDocumentStore = txn . store <
309- DbRemoteDocumentKey ,
310- DbRemoteDocument
311- > ( DbRemoteDocumentStore ) ;
312-
313- return remoteDocumentStore . iterate ( ( key , doc ) => {
314- doc . documentType = 0 ;
315- return remoteDocumentStore . put ( doc ) ;
316- } ) ;
317- }
318-
319310 private addDocumentGlobal (
320311 txn : SimpleDbTransaction
321312 ) : PersistencePromise < void > {
@@ -519,7 +510,8 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
519510 unknownDocument : legacyDocument . unknownDocument ,
520511 noDocument : legacyDocument . noDocument ,
521512 document : legacyDocument . document ,
522- hasCommittedMutations : ! ! legacyDocument . hasCommittedMutations
513+ hasCommittedMutations : ! ! legacyDocument . hasCommittedMutations ,
514+ documentType : 0
523515 } ;
524516 writes . push ( remoteDocumentStore . put ( dbRemoteDocument ) ) ;
525517 } )
@@ -813,3 +805,26 @@ function extractKey(remoteDoc: DbRemoteDocumentLegacy): DocumentKey {
813805 return fail ( 0x8faf , 'Unexpected DbRemoteDocument' ) ;
814806 }
815807}
808+
809+ function createRemoteDocumentStoreDocumentTypeIndex ( txn : IDBTransaction ) : void {
810+ txn
811+ . objectStore ( DbRemoteDocumentStore )
812+ . createIndex (
813+ DbRemoteDocumentCollectionIndex ,
814+ DbRemoteDocumentCollectionIndexPath ,
815+ { unique : false }
816+ ) ;
817+ }
818+
819+ function backfillRemoteDocumentStoreDocumentType (
820+ txn : SimpleDbTransaction
821+ ) : PersistencePromise < void > {
822+ const remoteDocumentStore = txn . store < DbRemoteDocumentKey , DbRemoteDocument > (
823+ DbRemoteDocumentStore
824+ ) ;
825+
826+ return remoteDocumentStore . iterate ( ( key , doc ) => {
827+ doc . documentType = 0 ;
828+ return remoteDocumentStore . put ( doc ) ;
829+ } ) ;
830+ }
0 commit comments