-
Notifications
You must be signed in to change notification settings - Fork 940
Fix the ordering of the index-based lookup in getAll(keys) #6128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
71df708
05475a3
3d875d2
0a4d45c
003a874
7c28b16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@firebase/firestore": patch | ||
--- | ||
|
||
Fixes an issue during multi-document lookup that resulted in the IndexedDB error "The parameter is less than or equal to this cursor's". |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -611,12 +611,29 @@ function dbCollectionGroupKey( | |
/* document id */ path.length > 0 ? path[path.length - 1] : '' | ||
]; | ||
} | ||
|
||
/** | ||
* Comparator that compares document keys according to the primary key sorting | ||
* used by the `DbRemoteDocumentDocument` store (by collection path and then | ||
* document ID). | ||
* used by the `DbRemoteDocumentDocument` store (by prefix path, collection id | ||
* and then document ID). | ||
* | ||
* Visible for testing. | ||
*/ | ||
function dbKeyComparator(l: DocumentKey, r: DocumentKey): number { | ||
const cmp = l.path.length - r.path.length; | ||
return cmp !== 0 ? cmp : DocumentKey.comparator(l, r); | ||
export function dbKeyComparator(l: DocumentKey, r: DocumentKey): number { | ||
const left = l.path.toArray(); | ||
const right = r.path.toArray(); | ||
|
||
let cmp = 0; | ||
for (let i = 0; i < left.length - 2 && i < right.length - 2; ++i) { | ||
cmp = primitiveComparator(left[i], right[i]); | ||
if (cmp) { | ||
return cmp; | ||
} | ||
} | ||
|
||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can we make it more explicit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JS compares by "thruhiness" and any non-null number is considered true. We could have something like:
That was my original code but it is pretty bloated. Let me know what you prefer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the bloated way.. |
||
primitiveComparator(left.length, right.length) || | ||
primitiveComparator(left[left.length - 2], right[right.length - 2]) || | ||
primitiveComparator(left[left.length - 1], right[right.length - 1]) | ||
); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.