gpt4 book ai didi

google-app-engine - Google Appengine 游标

转载 作者:太空宇宙 更新时间:2023-11-03 15:21:48 25 4
gpt4 key购买 nike

我在我的 python 应用引擎项目中同时使用了 ndbsearch-api 查询。

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

以下是我不清楚的地方:

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

最佳答案

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

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

关于google-app-engine - Google Appengine 游标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42007423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com