Google datastore - does it do lazy loading?

if i have a Customer object with a list of orders declared with db.ReferenceProperty

after a while I might have a huge number of orders, if I pull out a Customer object am I in danger of pulling a full set of orders?

+2


a source to share


1 answer


Yes, db.ReferenceProperty fields are lazy loaded. From the docs :

ReferenceProperty automatically refers to model instances and model instances as properties: the model instance can be directly bound to the ReferenceProperty and its key will be used. The ReferenceProperty value can be used as if it were a model instance, and the repository object would be fetched and the model instance created when it was first used this way. Pristine reference properties do not ask for unnecessary data.



So for example:

# Any reference properties not loaded yet
customer = Customer.get_by_id(1)
print customer.name
print customer.address

# Assuming customer.order is a ReferenceProperty, now is when it
# would be loaded from the datastore.
print customer.order.created_at

      

+6


a source







All Articles