@@ -298,90 +298,79 @@ export class IndexedDbIndexManager implements IndexManager {
298
298
let canServeTarget = true ;
299
299
const indexes = new Map < Target , FieldIndex | null > ( ) ;
300
300
301
- return indexEntries
302
- . count ( )
303
- . next ( count => {
304
- //console.log(`INDEX ENTRY COUNT: ${count}`);
305
- return PersistencePromise . forEach (
306
- this . getSubTargets ( target ) ,
307
- ( subTarget : Target ) => {
308
- return this . getFieldIndex ( transaction , subTarget ) . next ( index => {
309
- canServeTarget &&= ! ! index ;
310
- indexes . set ( subTarget , index ) ;
311
- } ) ;
312
- }
313
- ) ;
314
- } )
315
- . next ( ( ) => {
316
- if ( ! canServeTarget ) {
317
- return PersistencePromise . resolve ( null as DocumentKey [ ] | null ) ;
318
- } else {
319
- let existingKeys = documentKeySet ( ) ;
320
- const result : DocumentKey [ ] = [ ] ;
321
- return PersistencePromise . forEach ( indexes , ( index , subTarget ) => {
322
- logDebug (
323
- LOG_TAG ,
324
- `Using index ${ fieldIndexToString (
325
- index !
326
- ) } to execute ${ canonifyTarget ( target ) } `
327
- ) ;
328
-
329
- const arrayValues = targetGetArrayValues ( subTarget , index ! ) ;
330
- const notInValues = targetGetNotInValues ( subTarget , index ! ) ;
331
- const lowerBound = targetGetLowerBound ( subTarget , index ! ) ;
332
- const upperBound = targetGetUpperBound ( subTarget , index ! ) ;
333
-
334
- const lowerBoundEncoded = this . encodeBound (
335
- index ! ,
336
- subTarget ,
337
- lowerBound
338
- ) ;
339
- const upperBoundEncoded = this . encodeBound (
340
- index ! ,
341
- subTarget ,
342
- upperBound
343
- ) ;
344
- const notInEncoded = this . encodeValues (
345
- index ! ,
346
- subTarget ,
347
- notInValues
348
- ) ;
349
-
350
- const indexRanges = this . generateIndexRanges (
351
- index ! . indexId ,
352
- arrayValues ,
353
- lowerBoundEncoded ,
354
- lowerBound . inclusive ,
355
- upperBoundEncoded ,
356
- upperBound . inclusive ,
357
- notInEncoded
358
- ) ;
359
- return PersistencePromise . forEach (
360
- indexRanges ,
361
- ( indexRange : IDBKeyRange ) => {
362
- // console.log(`indexRange lower: ${JSON.stringify(indexRange.lower)}, upper: ${JSON.stringify(indexRange.upper)}`);
363
- // console.log(`indexRange lower: ${JSON.stringify(indexRange.lower[2])}, upper: ${JSON.stringify(indexRange.upper[2])}`);
364
- // console.log(`indexRange lower: ${JSON.stringify(indexRange.lowerOpen)}, upper: ${JSON.stringify(indexRange.upperOpen)}`);
365
- // console.log(`target.limit: ${target.limit}`);
366
- return indexEntries
367
- . loadFirst ( indexRange , target . limit )
368
- . next ( entries => {
369
- // console.log(JSON.stringify(entries));
370
- entries . forEach ( entry => {
371
- const documentKey = DocumentKey . fromSegments (
372
- entry . documentKey
373
- ) ;
374
- if ( ! existingKeys . has ( documentKey ) ) {
375
- existingKeys = existingKeys . add ( documentKey ) ;
376
- result . push ( documentKey ) ;
377
- }
378
- } ) ;
301
+ return PersistencePromise . forEach (
302
+ this . getSubTargets ( target ) ,
303
+ ( subTarget : Target ) => {
304
+ return this . getFieldIndex ( transaction , subTarget ) . next ( index => {
305
+ canServeTarget &&= ! ! index ;
306
+ indexes . set ( subTarget , index ) ;
307
+ } ) ;
308
+ }
309
+ ) . next ( ( ) => {
310
+ if ( ! canServeTarget ) {
311
+ return PersistencePromise . resolve ( null as DocumentKey [ ] | null ) ;
312
+ } else {
313
+ let existingKeys = documentKeySet ( ) ;
314
+ const result : DocumentKey [ ] = [ ] ;
315
+ return PersistencePromise . forEach ( indexes , ( index , subTarget ) => {
316
+ logDebug (
317
+ LOG_TAG ,
318
+ `Using index ${ fieldIndexToString (
319
+ index !
320
+ ) } to execute ${ canonifyTarget ( target ) } `
321
+ ) ;
322
+
323
+ const arrayValues = targetGetArrayValues ( subTarget , index ! ) ;
324
+ const notInValues = targetGetNotInValues ( subTarget , index ! ) ;
325
+ const lowerBound = targetGetLowerBound ( subTarget , index ! ) ;
326
+ const upperBound = targetGetUpperBound ( subTarget , index ! ) ;
327
+
328
+ const lowerBoundEncoded = this . encodeBound (
329
+ index ! ,
330
+ subTarget ,
331
+ lowerBound
332
+ ) ;
333
+ const upperBoundEncoded = this . encodeBound (
334
+ index ! ,
335
+ subTarget ,
336
+ upperBound
337
+ ) ;
338
+ const notInEncoded = this . encodeValues (
339
+ index ! ,
340
+ subTarget ,
341
+ notInValues
342
+ ) ;
343
+
344
+ const indexRanges = this . generateIndexRanges (
345
+ index ! . indexId ,
346
+ arrayValues ,
347
+ lowerBoundEncoded ,
348
+ lowerBound . inclusive ,
349
+ upperBoundEncoded ,
350
+ upperBound . inclusive ,
351
+ notInEncoded
352
+ ) ;
353
+ return PersistencePromise . forEach (
354
+ indexRanges ,
355
+ ( indexRange : IDBKeyRange ) => {
356
+ return indexEntries
357
+ . loadFirst ( indexRange , target . limit )
358
+ . next ( entries => {
359
+ entries . forEach ( entry => {
360
+ const documentKey = DocumentKey . fromSegments (
361
+ entry . documentKey
362
+ ) ;
363
+ if ( ! existingKeys . has ( documentKey ) ) {
364
+ existingKeys = existingKeys . add ( documentKey ) ;
365
+ result . push ( documentKey ) ;
366
+ }
379
367
} ) ;
380
- }
381
- ) ;
382
- } ) . next ( ( ) => result as DocumentKey [ ] | null ) ;
383
- }
384
- } ) ;
368
+ } ) ;
369
+ }
370
+ ) ;
371
+ } ) . next ( ( ) => result as DocumentKey [ ] | null ) ;
372
+ }
373
+ } ) ;
385
374
}
386
375
387
376
private getSubTargets ( target : Target ) : Target [ ] {
@@ -475,8 +464,8 @@ export class IndexedDbIndexManager implements IndexManager {
475
464
/** Generates the lower bound for `arrayValue` and `directionalValue`. */
476
465
private generateLowerBound (
477
466
indexId : number ,
478
- arrayValue : Uint8Array | number [ ] ,
479
- directionalValue : Uint8Array | number [ ] ,
467
+ arrayValue : Uint8Array ,
468
+ directionalValue : Uint8Array ,
480
469
inclusive : boolean
481
470
) : IndexEntry {
482
471
const entry = new IndexEntry (
@@ -491,8 +480,8 @@ export class IndexedDbIndexManager implements IndexManager {
491
480
/** Generates the upper bound for `arrayValue` and `directionalValue`. */
492
481
private generateUpperBound (
493
482
indexId : number ,
494
- arrayValue : Uint8Array | number [ ] ,
495
- directionalValue : Uint8Array | number [ ] ,
483
+ arrayValue : Uint8Array ,
484
+ directionalValue : Uint8Array ,
496
485
inclusive : boolean
497
486
) : IndexEntry {
498
487
const entry = new IndexEntry (
0 commit comments