【发布时间】:2014-03-12 11:55:26
【问题描述】:
我使用 GAE NDB Python 2.7
我的两个模型代码:
class A(ndb.Model):
def X(self, value):
:: # some statements to return a value
return range
def Y(self, value):
:: # some statements to return a value
return range
def Z(self, value):
:: # some statements to return a value
return range
property_1 = ndb.IntegerProperty(default=0, indexed=False)
property_2 = ndb.IntegerProperty(default=0, indexed=False)
property_3 = ndb.IntegerProperty(default=0, indexed=False)
property_4 = ndb.IntegerProperty(indexed=False)
# Computed values
computed_property_1 = ndb.ComputedProperty(lambda e: e.X(e.property_1))
computed_property_2 = ndb.ComputedProperty(lambda e: e.Y(e.property_2))
computed_property_3 = ndb.ComputedProperty(lambda e: e.Z(e.property_3))
date_added = ndb.DateTimeProperty(auto_now_add=True, indexed=False)
date_modified = ndb.DateTimeProperty(auto_now=True, indexed=False)
class B(ndb.Model):
property_5 = ndb.IntegerProperty()
property_6 = ndb.StructuredProperty(A)
date_added = ndb.DateTimeProperty(auto_now_add=True, indexed=False)
date_modified = ndb.DateTimeProperty(auto_now=True, indexed=False)
我的查询代码:
qry_1 = B.query(B.property_5==input_value) # or B.query(B.property_6.computed_property_2==input_value)
record_list = qry_1.fetch()
当我对模型B的实体执行上述查询时,是否会执行任何写操作? (尤其是 ComputedProperty 和 DateTimeProperty(with "auto_now") 属性)
如果是,是否会限制为每秒 1 次写入(我认为这是免费应用程序的限制)
如果是,并且如果我有 50 个与查询匹配的实体,是否会在完成查询并返回匹配的实体集(查询完成时间的任何估计)之前先完成写入操作(如上所述)
如果我在 B 类中替换以下行,上述答案有什么不同
property_6 = ndb.StructuredProperty(A)
与
property_6 = ndb.StructuredProperty(A, repeated=True)
【问题讨论】:
-
B 类没有 property_3 属性。是不是笔误?
-
@SlawekRewaj 谢谢,抱歉打错了..我已经更正了..
-
1 次写入/秒的限制适用于免费和付费应用。实际上意味着每个实体组 1 次写入/秒。实体组通过共享相同的父级(也称为祖先)和强一致性查询来允许事务或交叉事务。这种限制很容易成为您的应用程序的瓶颈,并使其无法扩展。因此,对实体组进行建模是有意义的,即使有数万亿用户使用您的应用程序,也不太可能达到此限制。例如:评论/帖子将用户作为父级。用户每秒执行超过 1 次写入操作的可能性不大。
标签: python google-app-engine google-cloud-datastore app-engine-ndb