Google Appengine 游标

Google Appengine Cursors

我在我的 python appengine 项目中同时使用 ndbsearch-api 查询。

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

以下内容我不清楚:

  1. 什么是游标生存时间?我可以公开 year-old 游标吗?
  2. 如果项目 added/removed 来自原始集合,光标分页将如何表现? (+ 如果光标指向特定记录,如果该记录不再存在会发生什么情况?)
  3. 查询顺序如何影响上面的内容?
  4. ndb 和 search-api 游标之间有什么根本区别吗?

我是从ndb的角度回答的,我没用过搜索API。所有报价均来自您的第一个 link.

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

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

因此,游标的年龄(即其查询的年龄)并不重要,因为必须恢复其 原始查询 才能获得游标。

对于 2:

Cursors and data updates

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.

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.

Limitations of cursors 的 Java 等效页面提到了一些可能因不一致而引发的错误:

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 也会引发一些类似的错误。