Skip to content

Commit 7c28b16

Browse files
Feedback
1 parent 003a874 commit 7c28b16

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/firestore/src/local/indexeddb_remote_document_cache.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ export function dbKeyComparator(l: DocumentKey, r: DocumentKey): number {
623623
const left = l.path.toArray();
624624
const right = r.path.toArray();
625625

626+
// The ordering is based on https://chromium.googlesource.com/chromium/blink/+/fe5c21fef94dae71c1c3344775b8d8a7f7e6d9ec/Source/modules/indexeddb/IDBKey.cpp#74
626627
let cmp = 0;
627628
for (let i = 0; i < left.length - 2 && i < right.length - 2; ++i) {
628629
cmp = primitiveComparator(left[i], right[i]);
@@ -631,9 +632,15 @@ export function dbKeyComparator(l: DocumentKey, r: DocumentKey): number {
631632
}
632633
}
633634

634-
return (
635-
primitiveComparator(left.length, right.length) ||
636-
primitiveComparator(left[left.length - 2], right[right.length - 2]) ||
637-
primitiveComparator(left[left.length - 1], right[right.length - 1])
638-
);
635+
cmp = primitiveComparator(left.length, right.length);
636+
if (cmp) {
637+
return cmp;
638+
}
639+
640+
cmp = primitiveComparator(left[left.length - 2], right[right.length - 2]);
641+
if (cmp) {
642+
return cmp;
643+
}
644+
645+
return primitiveComparator(left[left.length - 1], right[right.length - 1]);
639646
}

0 commit comments

Comments
 (0)