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

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

问题描述

我在我的 python appengine 项目中同时使用 ndbsearch-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 返回一组连续的结果数据存储.使用开始和结束游标检索结果时,您不能保证结果的大小相同就像您生成游标时一样.可以添加或删除实体从生成游标的时间到 Cloud Datastore当它们在查询中使用时.

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.

游标限制 提到了一些可能因不一致而引发的错误:

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天全站免登陆