【发布时间】:2017-06-01 07:08:58
【问题描述】:
我使用 NDB 查询通过 IN 运算符的键列表检索实体,然后按日期过滤。该查询被分解为几个子查询,这些子查询是用 doc 编写的。并按顺序而不是并行运行。
class Post(ndb.Model):
modified_date = ndb.DateTimeProperty()
# query
posts = Post.query(
Post.key.IN(keys),
Post.modified_date >= start_date,
Post.modified_date <= end_date).fetch()
查询分析图显示顺序运行的子查询。 25 个键大约需要 0.3 秒。查询延迟与要获取的键数成线性关系。
有什么方法可以优化查询,按键检索实体并按日期范围过滤的最佳做法是什么?
【问题讨论】:
标签: google-app-engine google-cloud-datastore app-engine-ndb google-app-engine-python