Skip to content

Commit 36f4a5a

Browse files
Implement Index Scanning
1 parent 07a3c6b commit 36f4a5a

File tree

12 files changed

+1400
-55
lines changed

12 files changed

+1400
-55
lines changed

packages/firestore/src/core/target.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,10 @@ export function targetGetLowerBound(
333333
filterValue = MIN_VALUE;
334334
break;
335335
case Operator.NOT_IN:
336-
const length = (fieldFilter.value.arrayValue!.values || []).length;
336+
// Porting Note: The Web SDK implements NotIn queries different from
337+
// Android and only uses a single element array as a NotIn bound.
337338
filterValue = {
338-
arrayValue: { values: new Array(length).fill(MIN_VALUE) }
339+
arrayValue: { values: [MIN_VALUE] }
339340
};
340341
break;
341342
default:
@@ -418,9 +419,10 @@ export function targetGetUpperBound(
418419
filterValue = MAX_VALUE;
419420
break;
420421
case Operator.NOT_IN:
421-
const length = (fieldFilter.value.arrayValue!.values || []).length;
422+
// Porting Note: The Web SDK implements NotIn queries different from
423+
// Android and only uses a single element array as a NotIn bound.
422424
filterValue = {
423-
arrayValue: { values: new Array(length).fill(MIN_VALUE) }
425+
arrayValue: { values: [MAX_VALUE] }
424426
};
425427
break;
426428
default:

packages/firestore/src/index/index_entry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function indexEntryComparator(
4949
return compareByteArrays(left.directionalValue, right.directionalValue);
5050
}
5151

52-
function compareByteArrays(left: Uint8Array, right: Uint8Array): number {
52+
export function compareByteArrays(left: Uint8Array, right: Uint8Array): number {
5353
for (let i = 0; i < left.length && i < right.length; ++i) {
5454
const compare = left[i] - right[i];
5555
if (compare !== 0) {

packages/firestore/src/local/index_manager.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,12 @@ export interface IndexManager {
103103

104104
/**
105105
* Returns the documents that match the given target based on the provided
106-
* index.
106+
* index. Returns `null` if the target does not have a matching index.
107107
*/
108108
getDocumentsMatchingTarget(
109109
transaction: PersistenceTransaction,
110-
fieldIndex: FieldIndex,
111110
target: Target
112-
): PersistencePromise<DocumentKeySet>;
111+
): PersistencePromise<DocumentKeySet | null>;
113112

114113
/**
115114
* Returns the next collection group to update. Returns `null` if no group

0 commit comments

Comments
 (0)