@@ -44,6 +44,7 @@ import {
4444 fieldIndexToString ,
4545 IndexKind ,
4646 IndexOffset ,
47+ indexOffsetComparator ,
4748 IndexSegment
4849} from '../model/field_index' ;
4950import { FieldPath , ResourcePath } from '../model/path' ;
@@ -469,15 +470,22 @@ export class IndexedDbIndexManager implements IndexManager {
469470 transaction : PersistenceTransaction ,
470471 target : Target
471472 ) : PersistencePromise < IndexType > {
472- // TODO(orqueries): We should look at the subtargets here
473- return this . getFieldIndex ( transaction , target ) . next ( index => {
474- if ( ! index ) {
475- return IndexType . NONE as IndexType ;
473+ let indexType = IndexType . FULL ;
474+ return PersistencePromise . forEach (
475+ this . getSubTargets ( target ) ,
476+ ( target : Target ) => {
477+ return this . getFieldIndex ( transaction , target ) . next ( index => {
478+ if ( ! index ) {
479+ indexType = IndexType . NONE ;
480+ } else if (
481+ indexType !== IndexType . NONE &&
482+ index . fields . length < targetGetSegmentCount ( target )
483+ ) {
484+ indexType = IndexType . PARTIAL ;
485+ }
486+ } ) ;
476487 }
477- return index . fields . length < targetGetSegmentCount ( target )
478- ? IndexType . PARTIAL
479- : IndexType . FULL ;
480- } ) ;
488+ ) . next ( ( ) => indexType ) ;
481489 }
482490
483491 /**
@@ -972,6 +980,28 @@ export class IndexedDbIndexManager implements IndexManager {
972980 }
973981 return ranges ;
974982 }
983+
984+ getMinOffset (
985+ transaction : PersistenceTransaction ,
986+ target : Target
987+ ) : PersistencePromise < IndexOffset > {
988+ let offset : IndexOffset | undefined ;
989+ return PersistencePromise . forEach (
990+ this . getSubTargets ( target ) ,
991+ ( target : Target ) => {
992+ return this . getFieldIndex ( transaction , target ) . next ( index => {
993+ if ( ! index ) {
994+ offset = IndexOffset . min ( ) ;
995+ } else if (
996+ ! offset ||
997+ indexOffsetComparator ( index . indexState . offset , offset ) < 0
998+ ) {
999+ offset = index . indexState . offset ;
1000+ }
1001+ } ) ;
1002+ }
1003+ ) . next ( ( ) => offset ! ) ;
1004+ }
9751005}
9761006
9771007/**
0 commit comments