Skip to content

Reducing limit over the life of a datastore query iterator. - #1787

Merged
dhermes merged 1 commit into
googleapis:masterfrom
dhermes:fix-1763
May 18, 2016
Merged

Reducing limit over the life of a datastore query iterator.#1787
dhermes merged 1 commit into
googleapis:masterfrom
dhermes:fix-1763

Conversation

@dhermes

Copy link
Copy Markdown
Contributor

Fixes#1763.

/cc @pcostell

@dhermesdhermes added the api: datastore Issues related to the Datastore API. label May 11, 2016
@googlebotgooglebot added the cla: yes This human has signed the Contributor License Agreement. label May 11, 2016
@dhermes

Copy link
Copy Markdown
ContributorAuthor

Sorry for the delay @pcostell!

Comment threadgcloud/datastore/query.py Outdated
break
if self._limit is not None:
self._limit -= len(self._page)
self.next_page()

This comment was marked as spam.

@dhermes

Copy link
Copy Markdown
ContributorAuthor

@pcostell PTAL, I also added logic for the offset

Comment threadgcloud/datastore/query.py Outdated
if self._limit is not None:
self._limit -= num_results
if self._offset is not None:
self._offset += num_results

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@dhermes

Copy link
Copy Markdown
ContributorAuthor

@pcostell You just mentioned that offset shouldn't be used to continue a query. You mean offset on it's own? Like without the end cursor?

Comment threadgcloud/datastore/query.py Outdated
if self._offset is not None:
# NOTE: The offset goes down relative to the location
# because we are updating the cursor each time.
self._offset -= num_results

This comment was marked as spam.

@pcostell

Copy link
Copy Markdown
Contributor

Sorry: When a query is continued, it may contain an offset. But like the limit the offset should always be decreasing. What I really mean:

Always use a cursor to step to the next batch of a query, never an offset.

Sometimes you need to go through batches of offset, in which you'll issue multiple queries with decreasing offsets. This is ok.

@dhermes

Copy link
Copy Markdown
ContributorAuthor

@pcostell PTAL.

@@ -382,7 +381,7 @@ class Iterator(object):
_query_pb2.QueryResultBatch.MORE_RESULTS_AFTER_LIMIT,

This comment was marked as spam.

This comment was marked as spam.

@dhermes

Copy link
Copy Markdown
ContributorAuthor

@tseaver I've got the LGTM from @pcostell. Can you give this a final pass?

self.assertTrue(iterator._query is query)
self.assertEqual(iterator._limit, None)
self.assertEqual(iterator._offset, 0)
self.assertEqual(iterator._offset, None)

This comment was marked as spam.

@tseaver

Copy link
Copy Markdown
Contributor

Tests for next_page should assert correct values for self._skipped_results.

@dhermes

Copy link
Copy Markdown
ContributorAuthor

@tseaver Good call. Check out the latest commit.

@tseaver

Copy link
Copy Markdown
Contributor

LGTM

In the process, also keeping tracking of the number of skipped
results (so that we can update the offset).
Fixesgoogleapis#1763.
@dhermes

Copy link
Copy Markdown
ContributorAuthor

Squashed commits. Will merge once Travis passes.

@dhermes
dhermes merged commit d956136 into googleapis:masterMay 18, 2016
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: datastoreIssues related to the Datastore API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@dhermes@pcostell@tseaver@googlebot