How to jump to specific page using Query Cursor?

旧巷老猫 提交于 2019-12-01 12:10:24

You can't. Datastore doesn't know the number of results found by your query.

You can however use some tricks to simulate a full pagination. For example one technique is to generate a certain number of cursors in a loop and generating the "last page" one.

Like in the following pseudo-code:

(results, next_curs, more) = model.query....fetch_page(...)

for p in xrange(5):
    # generate cursor for page number 'b' 
    # by using the next_cursor from previous page
    (results, next_curs, more) = model.....fetch_page(cursor=next_cursor,...)

As you don't access the results cursor the performance is somewhat acceptable (depending on your models complexity, query complexity and such). You can tweak it on your data.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!