-
Notifications
You must be signed in to change notification settings - Fork 943
Release Query.limitToLast(n) #2321
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
Conversation
… work with Target. (#2254)
…between Target and Query. (#2281)
* Add spec test for single client
… work with Target. (#2254)
…between Target and Query. (#2281)
* Add spec test for single client
…/firebase/firebase-js-sdk into wuandy/QueryTargetAndLimitToLast
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.
Some remaining nits about the code comments, but this looks really great. Let's ship it (and then port it to Android and iOS)! 👍
packages/firestore/CHANGELOG.md
Outdated
@@ -5,6 +5,8 @@ | |||
`.where()`. `in` finds documents where a specified field’s value is IN a | |||
specified array. `array-contains-any` finds documents where a specified field | |||
is an array and contains ANY element of a specified array. | |||
- [feature] Added `limitToLast(n: number)` to Firestore query, which returns |
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.
I would shorten this to:
Added Query.limitToLast(n: number)
, which returns the last n
documents as the result.
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.
Done.
packages/firestore-types/index.d.ts
Outdated
* documents. | ||
* | ||
* Queries with `limitToLast` must have at least one `orderBy` clause on | ||
* one of the document fields, or an Exception will throw during execution. |
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.
s/will throw/will be thrown/
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.
Done.
packages/firebase/index.d.ts
Outdated
* documents. | ||
* | ||
* You must specify at least one `orderBy` clause for `limitToLast` queries, | ||
* otherwise an exception will be thrown thrown during execution. |
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.
s/thrown thrown/thrown/
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.
Done.
packages/firestore/src/core/query.ts
Outdated
private memoizedOrderBy: OrderBy[] | null = null; | ||
|
||
// The corresponding `Target` of this `Query` instance. | ||
private target: Target | null = null; |
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.
Maybe rename this to memoizedTarget
?
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.
Done.
@@ -301,6 +307,18 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer { | |||
const queryView = this.queryViewsByQuery.get(query)!; | |||
assert(!!queryView, 'Trying to unlisten on query not found:' + query); | |||
|
|||
// If it's not the only query mapped to the target, only clean up | |||
// query view and keep the target active. |
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.
This would read better as:
"Only clean up the query view and target if this is the only query mapped to the target."
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.
Done.
* | ||
* The synthesized result might be different from the original `Query`, but | ||
* since the synthesized `Query` should return the same results as the | ||
* original one (only the presentation of results might differ), and this is |
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.
Suggest to drop and this is only used for multi-tab
for readability. The porting note should be sufficient.
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.
Done.
@@ -110,6 +110,9 @@ export interface SharedClientState { | |||
* Associates a new Query Target ID with the local Firestore client. Returns | |||
* the new query state for the query (which can be 'current' if the query is | |||
* already associated with another tab). | |||
* | |||
* If the target id is already associated with local client, the method simply | |||
* returns it's `QueryTargetState`. |
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.
s/it's/its/
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.
Done.
/** Starts new listen for the given query. Uses resume token if provided */ | ||
/** | ||
* Starts new listen for the given query. Uses resume token if provided. It | ||
* is a no-op if the target of given `QueryData` is already being listened. |
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.
s/listened/listened to/
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.
Done.
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.
Thanks for all the reviews!!
packages/firebase/index.d.ts
Outdated
* documents. | ||
* | ||
* You must specify at least one `orderBy` clause for `limitToLast` queries, | ||
* otherwise an exception will be thrown thrown during execution. |
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.
Done.
packages/firestore-types/index.d.ts
Outdated
* documents. | ||
* | ||
* Queries with `limitToLast` must have at least one `orderBy` clause on | ||
* one of the document fields, or an Exception will throw during execution. |
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.
Done.
packages/firestore/CHANGELOG.md
Outdated
@@ -5,6 +5,8 @@ | |||
`.where()`. `in` finds documents where a specified field’s value is IN a | |||
specified array. `array-contains-any` finds documents where a specified field | |||
is an array and contains ANY element of a specified array. | |||
- [feature] Added `limitToLast(n: number)` to Firestore query, which returns |
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.
Done.
packages/firestore/src/core/query.ts
Outdated
private memoizedOrderBy: OrderBy[] | null = null; | ||
|
||
// The corresponding `Target` of this `Query` instance. | ||
private target: Target | null = null; |
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.
Done.
@@ -301,6 +307,18 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer { | |||
const queryView = this.queryViewsByQuery.get(query)!; | |||
assert(!!queryView, 'Trying to unlisten on query not found:' + query); | |||
|
|||
// If it's not the only query mapped to the target, only clean up | |||
// query view and keep the target active. |
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.
Done.
* | ||
* The synthesized result might be different from the original `Query`, but | ||
* since the synthesized `Query` should return the same results as the | ||
* original one (only the presentation of results might differ), and this is |
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.
Done.
@@ -110,6 +110,9 @@ export interface SharedClientState { | |||
* Associates a new Query Target ID with the local Firestore client. Returns | |||
* the new query state for the query (which can be 'current' if the query is | |||
* already associated with another tab). | |||
* | |||
* If the target id is already associated with local client, the method simply | |||
* returns it's `QueryTargetState`. |
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.
Done.
/** Starts new listen for the given query. Uses resume token if provided */ | ||
/** | ||
* Starts new listen for the given query. Uses resume token if provided. It | ||
* is a no-op if the target of given `QueryData` is already being listened. |
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.
Done.
@Feiyang1 This PR adds a new Can you or someone from your team provide an owner approval on |
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.
Approved for the d.ts file changes.
Query
andTarget
in the SDK.limitToLast
.limitToLast
.