| OLD | NEW |
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed by the Apache v2.0 license that can be | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 from google.appengine.datastore import datastore_query | 5 from google.appengine.datastore import datastore_query |
| 6 from google.appengine.ext import ndb | 6 from google.appengine.ext import ndb |
| 7 | 7 |
| 8 | 8 |
| 9 def fetch_page(query, batch_size, cursor_str, **kwargs): | 9 def fetch_page(query, batch_size, cursor_str, **kwargs): |
| 10 """Fetches a page from a query. | 10 """Fetches a page from a query. |
| 11 | 11 |
| 12 Arguments: | 12 Arguments: |
| 13 query: ndb.Query. | 13 query: ndb.Query. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 28 raise ValueError( | 28 raise ValueError( |
| 29 'cursor must be between valid string, got %r', cursor_str) | 29 'cursor must be between valid string, got %r', cursor_str) |
| 30 cursor = datastore_query.Cursor(urlsafe=cursor_str) | 30 cursor = datastore_query.Cursor(urlsafe=cursor_str) |
| 31 else: | 31 else: |
| 32 cursor = None | 32 cursor = None |
| 33 items, cursor, more = query.fetch_page( | 33 items, cursor, more = query.fetch_page( |
| 34 batch_size, start_cursor=cursor, **kwargs) | 34 batch_size, start_cursor=cursor, **kwargs) |
| 35 if not more: | 35 if not more: |
| 36 return items, None | 36 return items, None |
| 37 return items, cursor.urlsafe() | 37 return items, cursor.urlsafe() |
| OLD | NEW |