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

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

问题描述

我使用 GAE NDB Python 2.7
我的两个模型代码:

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) 

我的查询代码:

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") 属性)

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)

如果是,是否将速率限制为每秒 1 次写入(我认为这是免费应用程序的限制)

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

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

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)

如果我替换 B 类中的以下行,上述答案有什么不同

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

property_6 = ndb.StructuredProperty(A)  

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

推荐答案

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

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天全站免登陆