-
Notifications
You must be signed in to change notification settings - Fork 943
Fix startAfter/endBefore for orderByKeys queries #4363
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 all commits
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,4 @@ | ||
--- | ||
'@firebase/database': patch | ||
--- | ||
Fixed an issue with startAfter/endBefore when used in orderByKey queries |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -289,13 +289,21 @@ export class QueryParams { | |
} | ||
|
||
startAfter(indexValue: unknown, key?: string | null): QueryParams { | ||
let childKey: string; | ||
if (key == null) { | ||
childKey = MAX_NAME; | ||
let params: QueryParams; | ||
if (this.index_ === KEY_INDEX) { | ||
if (typeof indexValue === 'string') { | ||
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. This check makes it so that startAfter still throws exceptions for incorrectly typed keys. 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. Where does it throw? Should we throw at the callsite to preserve the stacktrace of the original mistake? 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. It throws in validateQueryEndpoints_: https://github.com/firebase/firebase-js-sdk/blob/master/packages/database/src/api/Query.ts#L110 (this behavior is tested), which is the same place that startAt() and endAt() throw for this case. I think that the way it's done now the original mistake, passing a non-string key to |
||
indexValue = successor(indexValue as string); | ||
} | ||
params = this.startAt(indexValue, key); | ||
} else { | ||
childKey = successor(key); | ||
let childKey: string; | ||
if (key == null) { | ||
childKey = MAX_NAME; | ||
} else { | ||
childKey = successor(key); | ||
} | ||
params = this.startAt(indexValue, childKey); | ||
} | ||
const params: QueryParams = this.startAt(indexValue, childKey); | ||
params.startAfterSet_ = true; | ||
return params; | ||
} | ||
|
@@ -324,12 +332,20 @@ export class QueryParams { | |
|
||
endBefore(indexValue: unknown, key?: string | null): QueryParams { | ||
let childKey: string; | ||
if (key == null) { | ||
childKey = MIN_NAME; | ||
let params: QueryParams; | ||
if (this.index_ === KEY_INDEX) { | ||
if (typeof indexValue === 'string') { | ||
indexValue = predecessor(indexValue as string); | ||
} | ||
params = this.endAt(indexValue, key); | ||
} else { | ||
childKey = predecessor(key); | ||
if (key == null) { | ||
childKey = MIN_NAME; | ||
} else { | ||
childKey = predecessor(key); | ||
} | ||
params = this.endAt(indexValue, childKey); | ||
} | ||
const params: QueryParams = this.endAt(indexValue, childKey); | ||
params.endBeforeSet_ = true; | ||
return params; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These just revert a previous change.