@@ -44,6 +44,7 @@ import {
44
44
fieldIndexToString ,
45
45
IndexKind ,
46
46
IndexOffset ,
47
+ indexOffsetComparator ,
47
48
IndexSegment
48
49
} from '../model/field_index' ;
49
50
import { FieldPath , ResourcePath } from '../model/path' ;
@@ -462,15 +463,22 @@ export class IndexedDbIndexManager implements IndexManager {
462
463
transaction : PersistenceTransaction ,
463
464
target : Target
464
465
) : PersistencePromise < IndexType > {
465
- // TODO(orqueries): We should look at the subtargets here
466
- return this . getFieldIndex ( transaction , target ) . next ( index => {
467
- if ( ! index ) {
468
- return IndexType . NONE as IndexType ;
466
+ let indexType = IndexType . FULL ;
467
+ return PersistencePromise . forEach (
468
+ this . getSubTargets ( target ) ,
469
+ ( target : Target ) => {
470
+ return this . getFieldIndex ( transaction , target ) . next ( index => {
471
+ if ( ! index ) {
472
+ indexType = IndexType . NONE ;
473
+ } else if (
474
+ indexType !== IndexType . NONE &&
475
+ index . fields . length < targetGetSegmentCount ( target )
476
+ ) {
477
+ indexType = IndexType . PARTIAL ;
478
+ }
479
+ } ) ;
469
480
}
470
- return index . fields . length < targetGetSegmentCount ( target )
471
- ? IndexType . PARTIAL
472
- : IndexType . FULL ;
473
- } ) ;
481
+ ) . next ( ( ) => indexType ) ;
474
482
}
475
483
476
484
/**
@@ -965,6 +973,28 @@ export class IndexedDbIndexManager implements IndexManager {
965
973
}
966
974
return ranges ;
967
975
}
976
+
977
+ getMinOffset (
978
+ transaction : PersistenceTransaction ,
979
+ target : Target
980
+ ) : PersistencePromise < IndexOffset > {
981
+ let offset : IndexOffset | undefined ;
982
+ return PersistencePromise . forEach (
983
+ this . getSubTargets ( target ) ,
984
+ ( target : Target ) => {
985
+ return this . getFieldIndex ( transaction , target ) . next ( index => {
986
+ if ( ! index ) {
987
+ offset = IndexOffset . min ( ) ;
988
+ } else if (
989
+ ! offset ||
990
+ indexOffsetComparator ( index . indexState . offset , offset ) < 0
991
+ ) {
992
+ offset = index . indexState . offset ;
993
+ }
994
+ } ) ;
995
+ }
996
+ ) . next ( ( ) => offset ! ) ;
997
+ }
968
998
}
969
999
970
1000
/**
0 commit comments