Skip to content

datastore: fix runQuery end logic #1202

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 1 commit into from
Apr 5, 2016

Conversation

stephenplusplus
Copy link
Contributor

Fixes #1200

To Dos

@stephenplusplus stephenplusplus added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. api: datastore Issues related to the Datastore API. labels Apr 5, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 5, 2016
@stephenplusplus
Copy link
Contributor Author

@mcfarljw - feel free to try this branch out:

$ npm install --save stephenplusplus/gcloud-node

@pcostell - I'll need to think this through a little bit more, so no rush to review. However, if you catch anything I should be aware of, let me know!

@jgeewax
Copy link
Contributor

jgeewax commented Apr 5, 2016

Was this related to #1181 ?

@stephenplusplus stephenplusplus force-pushed the master branch 2 times, most recently from 816ba9a to 6ed5073 Compare April 5, 2016 11:55
@stephenplusplus
Copy link
Contributor Author

@pcostell -- after we get NOT_FINISHED, we build a nextQuery and run it to get the rest of the results. Previously, we didn't update the limit, so if a user ran a query that had a limit of 500, and we got a NOT_FINISHED before reaching 500, the nextQuery we run would still have a limit of 500, thus perpetually racking up all of the entities in the datastore, effectively ignoring the limit.

This PR sets nextQuery.limit = originalLimit - numReceivedEntities-- this is only for the NOT_FINISHED responses when we run nextQuery automatically for the user. When we stop getting NOT_FINISHED, we restore nextQuery.limit = originalQuery.limit and return nextQuery to the user.

@stephenplusplus
Copy link
Contributor Author

@jgeewax that was in reference our old logic, pre v1beta3: https://github.com/GoogleCloudPlatform/gcloud-node/blob/807a61641401e375c72d59b0535eaebe4f8a7e5b/lib/datastore/request.js#L644 -- which was changed when we released v1beta3: https://github.com/GoogleCloudPlatform/gcloud-node/blob/cd0c3e98505c5e29004d063b37a8605b7230a504/lib/datastore/request.js#L458 (discussion)

I thought it was "fixed" because we were no longer used the "entities.length" to determine if there were more results.

@jgeewax
Copy link
Contributor

jgeewax commented Apr 5, 2016

This seems weird to me.... (changing the nextQuery.limit value). Shouldn't the query cursor know what's up? and keep going until it hits 500?

@stephenplusplus
Copy link
Contributor Author

I'll have to defer to @pcostell on that one.

@pcostell
Copy link
Contributor

pcostell commented Apr 5, 2016

Ah sorry you're totally right, I should have seen this.

Yes you do have to track the limit (in the same way you have to track the offset).

@jgeewax -- the cursor is a static pointer, not just a page token. So, for example, you could use the cursor to issue the same query but backwards from that specific point.

if (originalLimitVal > -1) {
// Update the limit on the nextQuery to return only the amount of
// results originally asked for.
nextQuery.limit(originalLimitVal - entities.length);

This comment was marked as spam.

This comment was marked as spam.

@pcostell
Copy link
Contributor

pcostell commented Apr 5, 2016

LGTM (Although I've been wrong before :-) )

@stephenplusplus
Copy link
Contributor Author

:) Thanks for the review!

@stephenplusplus
Copy link
Contributor Author

@callmehiphop ptal 👍

@callmehiphop
Copy link
Contributor

@stephenplusplus could we benefit from an additional system test (or tests) here?

@stephenplusplus
Copy link
Contributor Author

I think that's a good idea, but I don't know how practical it is, since we need the API to return "NOT_FINISHED", which I've only reproduced when I am querying for upwards of 500 entities. Since we don't create that many entities in our tests, I'm not sure we can create this condition in the system tests, and might have to use our unit tests to catch it.

@callmehiphop callmehiphop merged commit 9d63eea into googleapis:master Apr 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. cla: yes This human has signed the Contributor License Agreement. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants