【发布时间】:2016-09-09 07:16:30
【问题描述】:
我已经实现了查询表的逻辑,对于该特定表中的每个实体,我必须查找另一个表。
例如
我的代码看起来像,
query = ndb.gql("select * from Foo where user = :1", user.key)
stories, next_cursor, more = query.fetch_page(size, start_cursor=cursor)
if next_cursor:
for story in stories:
print story.key
images = ndb.gql("select * from Images where story = :1", story.key)
for image in images:
print image.key
else:
#do some operations
你看,如果我们将大小设为 10 给 fetch_page 函数,它会分别找到 10 个实体。对于每个实体,我们必须查找另一种Image。
这种类型的数据存储查找需要 850 到 950 毫秒。我想减少这个 API 的响应时间。
请注意,我必须从 Story kind 和 Images kind 获取一些列值。
有没有办法通过使用get_multi 方法来缩短查询。或者,我有一个使用memcache 的想法,或者我们应该在Foo 模型中定义一个新的StructuredProperty,它的值必须是Images 模型实体的列表。
我不知道在这种情况下哪个适合..请指导我。
【问题讨论】:
标签: python performance google-app-engine google-cloud-datastore app-engine-ndb