Skip to content

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

Merged
merged 14 commits into from
Nov 2, 2019

Conversation

wu-hui
Copy link
Contributor

@wu-hui wu-hui commented Nov 1, 2019

  • Split Query and Target in the SDK.
  • Implement limitToLast.
  • Integration tests and spec tests for limitToLast.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a 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)! 👍

@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* documents.
*
* Queries with `limitToLast` must have at least one `orderBy` clause on
* one of the document fields, or an Exception will throw during execution.
Copy link
Contributor

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/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* documents.
*
* You must specify at least one `orderBy` clause for `limitToLast` queries,
* otherwise an exception will be thrown thrown during execution.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/thrown thrown/thrown/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

private memoizedOrderBy: OrderBy[] | null = null;

// The corresponding `Target` of this `Query` instance.
private target: Target | null = null;
Copy link
Contributor

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?

Copy link
Contributor Author

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.
Copy link
Contributor

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."

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/it's/its/

Copy link
Contributor Author

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/listened/listened to/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

@wu-hui wu-hui left a 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!!

* documents.
*
* You must specify at least one `orderBy` clause for `limitToLast` queries,
* otherwise an exception will be thrown thrown during execution.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* documents.
*
* Queries with `limitToLast` must have at least one `orderBy` clause on
* one of the document fields, or an Exception will throw during execution.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

private memoizedOrderBy: OrderBy[] | null = null;

// The corresponding `Target` of this `Query` instance.
private target: Target | null = null;
Copy link
Contributor Author

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.
Copy link
Contributor Author

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
Copy link
Contributor Author

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`.
Copy link
Contributor Author

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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@wu-hui wu-hui assigned Feiyang1 and unassigned wu-hui Nov 2, 2019
@wu-hui
Copy link
Contributor Author

wu-hui commented Nov 2, 2019

@Feiyang1 This PR adds a new limitToLast() method to firestore queries. Please see the API review doc here: go/limitToLast

Can you or someone from your team provide an owner approval on index.d.ts ?

Copy link
Member

@Feiyang1 Feiyang1 left a 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.

@Feiyang1 Feiyang1 assigned wu-hui and unassigned Feiyang1 Nov 2, 2019
@wu-hui wu-hui merged commit 3323467 into master Nov 2, 2019
@hsubox76 hsubox76 added this to the next milestone Nov 4, 2019
@firebase firebase locked and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants