【问题标题】:Questions about the behavior of getting Cursor of datastore关于获取数据存储区Cursor行为的问题
【发布时间】:2019-06-04 22:35:45
【问题描述】:

我有一个关于获取光标的问题

目标函数: https://godoc.org/google.golang.org/appengine/datastore#Iterator.Cursor

从以下代码可以看出,获取Cursor时设置了offset https://github.com/golang/appengine/blob/master/datastore/query.go#L702-L705

当我使用 GCP 控制台的堆栈跟踪执行此函数时检查结果时,Insights 显示警告

Issue: Use of offset in datastore queries.
Description: Your app made 1 remote procedure calls to datastore.query () and datastore.next () using offset.
Recommendation: Use cursor instead of offset.

查询详情

g.co/gae/datastore/offset 10
g.co/gae/datastore/skipped 10

偏移量会影响性能和计费,我想避免这种行为 有没有办法避免使用偏移量?或者这是正确的行为?

【问题讨论】:

标签: google-app-engine go google-cloud-platform google-cloud-datastore


【解决方案1】:

来自Offsets versus cursors

虽然 Cloud Datastore 支持整数偏移量,但您应该避免 使用它们。相反,使用游标。使用偏移量只能避免 将跳过的实体返回到您的应用程序,但这些实体 仍在内部检索。跳过的实体确实会影响 查询的延迟,并且您的应用程序需要为读取付费 检索它们所需的操作。使用游标代替偏移 让您避免所有这些费用。

您所指的q.offset 是用于Cursor 实现的内部变量,它不是上面引用提到的显式查询偏移量。

所以你应该没问题使用Cursor

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 2020-04-06
    • 2023-03-08
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多