Appengine游标如何运作? [英] How do appengine cursors work?

查看:142
本文介绍了Appengine游标如何运作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python appengine项目中同时使用了 ndb search-api 查询.

I'm using both ndb and search-api queries in my python appengine project.

我能找到的关于光标的唯一官方文档:

The only official docs on cursors I can find:

我不清楚以下事情:

  1. 什么是光标生存时间?我可以公开使用了多年的游标吗?
  2. 如果从原始集合中添加/删除了项目,则光标分页的行为如何?(+如果光标指向特定记录,如果该记录不再存在会发生什么?)
  3. 上面的查询顺序有何影响?
  4. ndb和search-api游标之间有根本区别吗?

推荐答案

我从 ndb 的角度回答,我没有使用搜索API.所有引号均来自您的第一个链接.

I'm answering from ndb perspective, I haven't use the search API. All quotes are from your first link.

对于1和3(因为从游标的角度来看,顺序被视为原始查询的一部分):

For 1 and 3 (as ordering is considered part of the original query from cursors perspective):

要从光标处检索其他结果,请应用程序准备一个具有相同实体类型的类似查询,过滤器和排序顺序,然后将游标传递到查询的执行检索之前的with_cursor()方法

To retrieve additional results from the point of the cursor, the application prepares a similar query with the same entity kind, filters, and sort orders, and passes the cursor to the query's with_cursor() method before performing the retrieval

因此,游标的年龄(即查询的年龄)实际上并不重要,因为必须还原其原始查询才能获取游标.

So it doesn't really matter how old the cursor is (i.e. how old its query is) since its original query must be restored for the cursor to be obtained.

对于2:

光标和数据更新

光标的位置定义为结果列表中的位置返回最后一个结果之后.光标不是在中的相对位置列表(不是偏移量);这是Cloud Datastore的标记开始索引扫描以获取结果时可以跳转.如果结果为查询在使用游标之间的变化,查询仅注意到变化发生在光标之后的结果中.如果之前出现新结果查询的光标位置,当提取游标后的结果.同样,如果实体为否较长的查询结果,但出现在光标之前,光标后出现的结果不会改变.如果最后结果返回结果已从结果集中删除,游标仍然知道如何找到下一个结果.

The cursor's position is defined as the location in the result list after the last result returned. A cursor is not a relative position in the list (it's not an offset); it's a marker to which Cloud Datastore can jump when starting an index scan for results. If the results for a query change between uses of a cursor, the query notices only changes that occur in results after the cursor. If a new result appears before the cursor's position for the query, it will not be returned when the results after the cursor are fetched. Similarly, if an entity is no longer a result for a query but had appeared before the cursor, the results that appear after the cursor do not change. If the last result returned is removed from the result set, the cursor still knows how to locate the next result.

检索查询结果时,可以同时使用开始光标和结束光标以从Cloud返回连续的一组结果数据存储.使用开始和结束光标检索结果时,您不能保证结果的大小将相同就像您生成游标时一样.实体可以添加或删除从生成游标的时间到在查询中使用它们时.

When retrieving query results, you can use both a start cursor and an end cursor to return a continuous group of results from Cloud Datastore. When using a start and end cursor to retrieve the results, you are not guaranteed that the size of the results will be the same as when you generated the cursors. Entities may be added or deleted from Cloud Datastore between the time the cursors are generated and when they are used in a query.

Java等效页面,位于游标的限制提到了一些可能因不一致而引起的错误:

The Java equivalent page at Limitations of cursors mentions some errors that can be raised for inconsistencies:

新的App Engine版本可能会更改内部实施详细信息,使依赖于它们的游标无效.如果应用程序尝试要使用不再有效的游标,Cloud Datastore会引发一个 IllegalArgumentException (低级API), JDOFatalUserException (JDO)或 PersistenceException (JPA).

New App Engine releases might change internal implementation details, invalidating cursors that depend on them. If an application attempts to use a cursor that is no longer valid, Cloud Datastore raises an IllegalArgumentException (low-level API), JDOFatalUserException (JDO), or PersistenceException (JPA).

怀疑 Python也将引发一些类似的错误.

I suspect Python would be raising some similar errors as well.

这篇关于Appengine游标如何运作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆