@@ -640,6 +640,10 @@ export class IndexedDbIndexManager implements IndexManager {
640
640
transaction : PersistenceTransaction ,
641
641
documents : DocumentMap
642
642
) : 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.
643
647
const memoizedIndexes = new Map < string , FieldIndex [ ] > ( ) ;
644
648
return PersistencePromise . forEach ( documents , ( key , doc ) => {
645
649
const memoizedCollectionIndexes = memoizedIndexes . get (
@@ -834,7 +838,7 @@ export class IndexedDbIndexManager implements IndexManager {
834
838
835
839
/**
836
840
* 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,
838
842
* '[foo > 2 && foo != 3]` becomes `[foo > 2 && < 3, foo > 3]`.
839
843
*/
840
844
private applyNotIn (
@@ -846,17 +850,17 @@ export class IndexedDbIndexManager implements IndexManager {
846
850
}
847
851
848
852
// The values need to be sorted so that we can return a sorted set of
849
- // non-overlapping ragnes .
853
+ // non-overlapping ranges .
850
854
notInValues . sort ( ( l , r ) => compareByteArrays ( l , r ) ) ;
851
855
852
856
const notInRanges : IDBKeyRange [ ] = [ ] ;
853
857
for ( const indexRange of indexRanges ) {
854
858
// 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
856
860
// the values from any notIn filter.
857
861
858
862
// The first index range starts with the lower bound and ends at the
859
- // first not in value (exclusive).
863
+ // first notIn value (exclusive).
860
864
notInRanges . push (
861
865
IDBKeyRange . bound (
862
866
indexRange . lower ,
@@ -867,7 +871,7 @@ export class IndexedDbIndexManager implements IndexManager {
867
871
) ;
868
872
869
873
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
871
875
// and ends at the next.
872
876
notInRanges . push (
873
877
IDBKeyRange . bound (
@@ -901,18 +905,18 @@ export class IndexedDbIndexManager implements IndexManager {
901
905
902
906
/**
903
907
* 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.
905
909
*/
906
910
private generateNotInBound (
907
- existingRange : IDBKeyRange ,
911
+ existingRange : DbIndexEntryKey ,
908
912
value : Uint8Array
909
913
) : DbIndexEntryKey {
910
914
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 ] ,
914
918
value ,
915
- ''
919
+ /* documentKey= */ ''
916
920
] ;
917
921
}
918
922
}
0 commit comments