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

Datastore: runQuery limit/cursors usage not clear #195

Closed
dwsupplee opened this issue Oct 8, 2016 · 4 comments
Closed

Datastore: runQuery limit/cursors usage not clear #195

dwsupplee opened this issue Oct 8, 2016 · 4 comments
Assignees
Labels
api: datastore Issues related to the Datastore API. 🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@dwsupplee
Copy link
Contributor

dwsupplee commented Oct 8, 2016

DatastoreClient::runQuery paginates through all results regardless of limit/cursors that are set. This leads to some slightly unexpected behavior in cases like the following:

// Assuming there are 5 results of kind 'Person'
$query = $datastore->query()
    ->kind('Person')
    ->limit(1);
$results = $datastore->runQuery($query);

echo count(iterator_to_array($results)); // 5

It takes more intimate knowledge of the library to realize that Query::limit() is only limiting the number of results per call to the API.

To limit the results returned from the API and only get a single item one must do the following:

$limit = 1;
$query = $datastore->query()
    ->kind('Person')
    ->limit($limit);
$results = $datastore->runQuery($query);

foreach ($results as $key => $result) {
    if ($key === $limit) {
        break;
    }

    echo $result->get();
}

Would we be able to consider not automatically paging when a limit/cursor are set, or document the behavior more clearly?

Thanks! :)

@dwsupplee dwsupplee added auth api: datastore Issues related to the Datastore API. labels Oct 8, 2016
@dwsupplee dwsupplee removed the auth label Oct 9, 2016
@kaliseo
Copy link

kaliseo commented Oct 9, 2016

Seriously ? oO One big problem identified is that if you have thousands of entities, it will cost a lot if i use someting like <=x

@jdpedrie
Copy link
Contributor

jdpedrie commented Oct 9, 2016

@dwsupplee Maybe we should change limit to set a true limit on the result set (essentially prevent paging), and add a resultsPerPage method to do what we're doing now?

@dwsupplee
Copy link
Contributor Author

Closed by #200

@tmatsuo
Copy link
Contributor

tmatsuo commented Oct 11, 2016

JFYI our tests pass now

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 7, 2020
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. 🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

5 participants