Read and Write Operations involved with ComputedProperty in GAE NDB

╄→尐↘猪︶ㄣ 提交于 2019-12-23 00:50:09

问题


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)  

回答1:


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



来源:https://stackoverflow.com/questions/22350743/read-and-write-operations-involved-with-computedproperty-in-gae-ndb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!