简体   繁体   English

GAE数据存储-是否存在下一页/是否存在x + 1个实体?

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

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 terms 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. 我需要在10个结果之后提取游标,但我需要获取11个以查看是否有后续页面。

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. 如果您立即获取11个项目,则只需获取1个额外的项目即可知道是否有下一页。 And you can just display the first 10 results and use the 11th result only as a "next page" indicator. 而且,您仅可以显示前10个结果并将第11个结果仅用作“下一页”指示符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM