如何判断返回的光标是否是 App Engine 中的最后一个光标
如果我遗漏了一些非常明显的东西,我深表歉意。
我正在使用光标连续调用应用程序引擎。如何判断我是否位于最后一个光标上?我现在执行的当前方法是保存最后一个光标,然后测试该光标是否等于当前返回的光标。这需要对数据存储进行额外的调用,但这可能是不必要的。
有更好的方法吗?
谢谢!
I apologize if I am missing something really obvious.
I'm making successive calls to app engine using cursors. How do I tell if the I'm on the last cursor? The current way I'm doing it now is to save the last cursor and then testing to see if that cursor equals the currently returned cursor. This requires an extra call to the datastore which is probably unnecessary though.
Is there a better way to do this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为没有办法在单个数据存储区调用中使用 ext.db 来执行此操作,而是使用 ndb 这是可能的。示例:
如果使用返回的游标将导致更多记录,则
more
将为True
。这是在单个 RPC 调用中巧妙完成的。I don't think there's a way to do this with ext.db in a single datastore call, but with ndb it is possible. Example:
If using the returned cursor will result in more records,
more
will beTrue
. This is done smartly, in a single RPC call.既然您说“最后一个游标”,我假设您正在使用游标进行某种分页,这意味着您将使用
限制
批量获取结果。在这种情况下,当返回的结果少于限制时,您就知道您位于最后一个光标。
Since you say 'last cursor' I assume you are using cursors for some kind of pagination, which implies you will be fetching results in batches with a
limit
.In this case then you know you are on the last cursor when you have less results returned than your limit.
如果您的意思是“此光标是否已到达搜索结果的末尾”,那么不,除非拿起光标并再次尝试。如果添加更多与原始搜索条件匹配的实体,以便它们在逻辑上落在光标“之后”(例如,按升序时间戳排序的查询),则重用已保存的光标将允许您检索这些新实体。
If you mean "has this cursor hit the end of the search results", then no, not without picking the cursor up and trying it again. If more entities are added that match the original search criteria, such that they logically land "after" the cursor (e.g., a query that sorts by an ascending timestamp), then reusing that saved cursor will let you retrieve those new entities.
我使用 Chris Familoe 描述的相同技术,但设置的限制比我希望返回的多 1。因此,在 Chris 的示例中,我将获取 101 个实体。返回 101 意味着我还有另一页至少有 1 个。
I use the same technique Chris Familoe describes, but set the limit 1 more than I wish to return. So, in Chris' example, I would fetch 101 entities. 101 returned means I have another page with at least 1 on.
我知道这篇文章有点旧,但我一直在寻找同一问题的解决方案。我在这本优秀的书中找到了它:
http://shop.oreilly.com/product/0636920017547.do
这是提示:
I know this post is kind of old but I was looking for a solution to the same problem. I found it in this excellent book:
http://shop.oreilly.com/product/0636920017547.do
Here is the tip: