开发者

GAE Datastore - Is there a next page / Are there x+1 entities?

开发者 https://www.devze.com 2023-01-13 08:27 出处:网络
Currently, to determine whether or not there is a next page of entities I\'m using the following code:

Currently, to determine whether or not there is a next page of entities I'm using the following code:

q = Entity.all().fetch(10)
cursor = q.cursor()
extra = q.fetch(1)

has_next_page = False
if extra:
  has_next_page = True

However, this is very expensive in 开发者_StackOverflowterms of the time it takes to execute the 'extra' query. I need to extract the cursor after 10 results, but I need to fetch 11 to see if there is a succeeding page.

Anyone have any better methods?


If you fetch 11 items straight away you'll only have to fetch 1 extra item to know if there is a next page or not. And you can just display the first 10 results and use the 11th result only as a "next page" indicator.

0

精彩评论

暂无评论...
验证码 换一张
取 消