【发布时间】:2014-08-10 20:58:36
【问题描述】:
我正在使用高复制数据存储以及ndb。我有一个kind 有超过 27,000 个实体,这不算多。假设数据存储区在查询和提取大量数据方面效率很高,但是每当我查询这种类型的数据时,查询都需要很长时间才能完成(我什至遇到了 DeadlineExceededErrors)。
我有一个模型,用于存储要在 Google 中编制索引的关键字和 URL:
class Keywords(ndb.Model):
keyword = ndb.StringProperty(indexed=True)
url = ndb.StringProperty(indexed=True)
number_articles = ndb.IntegerProperty(indexed=True)
# Some other attributes... All attributes are indexed
我目前的用例是构建我的站点地图,并获取我的前 20 个关键字以从我的希望页面链接。
当我获取许多实体时,我通常会这样做:
Keywords.query().fetch() # For the sitemap, as I want all of the urls
Keywords.query(Keywords.number_articles > 5).fetch() # For the homepage, I want to link to keywords with more than 5 articles
有没有更好的方法来提取数据?
我尝试将数据索引到 Search API 中,并且我看到了巨大的速度提升。尽管这可行,但我认为将数据从 Datastore 复制到具有基本相同字段的 Search API 并不理想。
提前致谢!
【问题讨论】:
-
您是否有涵盖您正在应用的过滤器的索引?
-
你需要解释你的用例。为什么您需要一次获取所有这些? :-/
-
您需要什么?为什么要一次获取所有实体?通常,我们使用寻呼机,如果您想为每个实体创建一个流程,您只需要在寻呼机上进行迭代。
-
我已经更新了帖子,提供了更多详细信息和用例,谢谢!
标签: python-2.7 google-app-engine google-cloud-datastore app-engine-ndb