@@ -640,6 +640,10 @@ export class IndexedDbIndexManager implements IndexManager {
640640 transaction : PersistenceTransaction ,
641641 documents : DocumentMap
642642 ) : PersistencePromise < void > {
643+ // Porting Note: `getFieldIndexes()` on Web does not cache index lookups as
644+ // it could be used across different IndexedDB transactions. As any cached
645+ // data might invalidated by other multi-tab clients, we can only trust data
646+ // within a single IndexedDB transaction. We therefore add a cache here.
643647 const memoizedIndexes = new Map < string , FieldIndex [ ] > ( ) ;
644648 return PersistencePromise . forEach ( documents , ( key , doc ) => {
645649 const memoizedCollectionIndexes = memoizedIndexes . get (
@@ -834,7 +838,7 @@ export class IndexedDbIndexManager implements IndexManager {
834838
835839 /**
836840 * Applies notIn and != filters by taking the provided ranges and excluding
837- * any values that match `notInValue` from these ranges. As an example,
841+ * any values that match the `notInValue` from these ranges. As an example,
838842 * '[foo > 2 && foo != 3]` becomes `[foo > 2 && < 3, foo > 3]`.
839843 */
840844 private applyNotIn (
@@ -846,17 +850,17 @@ export class IndexedDbIndexManager implements IndexManager {
846850 }
847851
848852 // The values need to be sorted so that we can return a sorted set of
849- // non-overlapping ragnes .
853+ // non-overlapping ranges .
850854 notInValues . sort ( ( l , r ) => compareByteArrays ( l , r ) ) ;
851855
852856 const notInRanges : IDBKeyRange [ ] = [ ] ;
853857 for ( const indexRange of indexRanges ) {
854858 // Use the existing bounds and interleave the notIn values. This means
855- // that we would split an existing range into two ranges that exclude
859+ // that we would split an existing range into multiple ranges that exclude
856860 // the values from any notIn filter.
857861
858862 // The first index range starts with the lower bound and ends at the
859- // first not in value (exclusive).
863+ // first notIn value (exclusive).
860864 notInRanges . push (
861865 IDBKeyRange . bound (
862866 indexRange . lower ,
@@ -867,7 +871,7 @@ export class IndexedDbIndexManager implements IndexManager {
867871 ) ;
868872
869873 for ( let i = 1 ; i < notInValues . length - 1 ; ++ i ) {
870- // Each index range that we need to scan starts at the last not in value
874+ // Each index range that we need to scan starts at the last notIn value
871875 // and ends at the next.
872876 notInRanges . push (
873877 IDBKeyRange . bound (
@@ -901,18 +905,18 @@ export class IndexedDbIndexManager implements IndexManager {
901905
902906 /**
903907 * Generates the index entry that can be used to create the cutoff for `value`
904- * on the provided index range..
908+ * on the provided index range.
905909 */
906910 private generateNotInBound (
907- existingRange : IDBKeyRange ,
911+ existingRange : DbIndexEntryKey ,
908912 value : Uint8Array
909913 ) : DbIndexEntryKey {
910914 return [
911- /* indexId= */ existingRange . lower [ 0 ] ,
912- /* userId= */ existingRange . lower [ 1 ] ,
913- /* arrayValue= */ existingRange . lower [ 2 ] ,
915+ /* indexId= */ existingRange [ 0 ] ,
916+ /* userId= */ existingRange [ 1 ] ,
917+ /* arrayValue= */ existingRange [ 2 ] ,
914918 value ,
915- ''
919+ /* documentKey= */ ''
916920 ] ;
917921 }
918922}
0 commit comments