Skip to content
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

feat: add support for Query.limitToLast() #954

Merged
merged 4 commits into from
Mar 11, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Mar 5, 2020

Fixes #945

This adds support for limitToLast(), including order reserving for queries. Fortunately, Watch uses its own comparator, so we don't have to reverse the results in Watch.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 5, 2020
@schmidt-sebastian schmidt-sebastian changed the title feat: support limitToLast WIP feat: add support for Query.limitToLast() Mar 10, 2020
@codecov
Copy link

codecov bot commented Mar 10, 2020

Codecov Report

Merging #954 into master will decrease coverage by 0.08%.
The diff coverage is 99.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #954      +/-   ##
==========================================
- Coverage   97.54%   97.45%   -0.09%     
==========================================
  Files          25       25              
  Lines       15896    15983      +87     
  Branches     1268     1208      -60     
==========================================
+ Hits        15506    15577      +71     
- Misses        387      403      +16     
  Partials        3        3
Impacted Files Coverage Δ
dev/src/reference.ts 99.8% <99.14%> (-0.08%) ⬇️
dev/src/order.ts 98.09% <0%> (-1.15%) ⬇️
dev/src/pool.ts 97.75% <0%> (-0.9%) ⬇️
dev/src/transaction.ts 96.47% <0%> (-0.51%) ⬇️
dev/src/watch.ts 98.77% <0%> (-0.37%) ⬇️
dev/src/serializer.ts 98.77% <0%> (-0.25%) ⬇️
dev/src/validate.ts 98.05% <0%> (-0.25%) ⬇️
dev/src/index.ts 98.62% <0%> (-0.07%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 12982cd...8c02c9c. Read the comment docs.

@@ -969,6 +969,15 @@ interface QueryCursor {
values: unknown[];
}

/*!
Copy link
Contributor

Choose a reason for hiding this comment

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

Ultranit: should it be /**?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"/?*" in JSDoc hides the comments from the public docs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I learn something new.

}

/**
* Creates and returns a new Query that only returns the last matching
Copy link
Contributor

Choose a reason for hiding this comment

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

We should update limit()'s comment to mirror the wording there as well.

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.

});

// Swap the cursors to match the now-flipped query ordering.
structuredQuery.startAt = this.toCursor(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest keeping the cursor reverse logic here instead of inside toCursor, because the order flipping is also done in this block and that makes the intention more explicit IMHO, and that is also how we do it in other SDKs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not a huge fan of the code this creates, but it makes sense to keep in aligned with the rest of our SDKs.

@@ -1898,13 +1993,13 @@ export class Query<T = DocumentData> {
}

/**
* Internal streaming method that accepts an optional transaction id.
* Internal streaming method that accepts the requets proto.
Copy link
Contributor

Choose a reason for hiding this comment

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

s/requests/request.

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

@@ -903,6 +903,21 @@ declare namespace FirebaseFirestore {
* @return The created Query.
*/
limit(limit: number): Query<T>;

/**
* Creates and returns a new Query that only returns the last matching
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment about bringing limit()'s comment in the same wording.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also done here.

@@ -1079,6 +1079,18 @@ describe('Query class', () => {
});
};

function addDocs(...data: DocumentData[]): Promise<WriteResult[]> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice refactoring!

@@ -1820,6 +1794,29 @@ describe('Query class', () => {
unsubscribe();
});
});

it('orders limitToLast() correctly', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be moved to other limitToLast tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is an integration test (in system-test/) and thus cannot be moved.


it('expects number', () => {
const query = firestore.collection('collectionId');
expect(() => query.limit(Infinity)).to.throw(
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be limitToLast instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes!

Copy link
Contributor

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

Mostly LGTM. Thanks for helping porting this!

@wu-hui wu-hui assigned schmidt-sebastian and unassigned wu-hui Mar 11, 2020
Copy link
Contributor

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

LGTM, thanks!

@wu-hui wu-hui removed their assignment Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

limitToLast
3 participants