在GAE NDB中涉及ComputedProperty的读写操作 [英] Read and Write Operations involved with ComputedProperty in GAE NDB

查看:91
本文介绍了在GAE NDB中涉及ComputedProperty的读写操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用GAE NDB Python 2.7

我的两个模型代码:

  class A(ndb。模型):
def X(self,value):
::#返回值的某些语句
返回范围
def Y(self,value):
::#一些语句返回值
返回范围
def Z(self,value):
::#返回值的一些语句
返回范围

property_1 = ndb.IntegerProperty(default = 0,indexed = False)
property_2 = ndb.InteProProperty(default = 0,indexed = False)
property_3 = ndb.IntegerProperty(default = 0, indexed = False)
property_4 = ndb.IntegerProperty(indexed = False)
#计算值
computed_property_1 = ndb.ComputedProperty(lambda e:eX(e.property_1))
computed_property_2 = ndb.ComputedProperty(lambda e:eY(e.property_2))
computed_property_3 = ndb.ComputedProperty(lambda e:eZ(e.property_3))
date_adde d = 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(带有auto_now)属性)

如果是,它会被限制为每秒1次写入(我认为这是极限对于免费应用程序)



如果是,并且如果我有50个匹配查询的实体,它会在完成查询并返回之前首先完成写入操作匹配的实体集合(对查询完成时间的任何估计)

如果我在B类中替换以下行,则上述答案中的任何差异

  property_6 = ndb.StructuredProperty(A)



带有

  property_6 = ndb.StructuredProperty(A,重复= True)


解决方案

执行查询时没有写入操作。这同样适用于StructuredProperty的两个变体。另外 auto_now_add auto_now 仅在写入操作期间设置。我不是100%确定的,但据我了解文档,计算属性也写在更新(我还没有使用它们)。


I use GAE NDB Python 2.7
My two Models code:

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) 

My Query code:

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() 

When I perform the above query on entity of model B, would any write operation be performed? (especially for the ComputedProperty and DateTimeProperty(with "auto_now") properties)

If yes, would it be rate limited to 1 write per second (i think that is the limit for free apps)

If yes, and if i have 50 entities matching the query, would it first complete the write operation(mentioned above) before completing the query and returning the matched entity set (any estimate of the query completion time)

Any difference in the above answers if I replace the following line in class B

property_6 = ndb.StructuredProperty(A)  

with

property_6 = ndb.StructuredProperty(A, repeated=True)  

解决方案

There are no write operations by performing queries. The same applies to the two variations with StructuredProperty. Also auto_now_add and auto_now are only set during write operations. I'm not 100% sure, but as far as I understand the docs, computed properties are also updated at write (I haven't used them yet).

这篇关于在GAE NDB中涉及ComputedProperty的读写操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆