I am currently storing data in my appengine ndb datastore using this model
class BundleModel (ndb.Model):
product_vals=ndb.StructuredProperty(ProductModel,repeated=True)
ProductModel is as follows:
class ProductModel(ndb.Model):
p_created=ndb.DateTimeProperty(auto_now_add=True)
p_updated=ndb.DateTimeProperty(auto_now=True)
p_title=ndb.StringProperty()
p_link=ndb.StringProperty()
p_categ=ndb.StringProperty()
p_categ_alt=ndb.StringProperty()
p_value=ndb.FloatProperty()
p_location=ndb.StringProperty()
p_avail=ndb.BooleanProperty(default=True)
p_mod=ndb.BooleanProperty(default=False)
I only put BundleModel in the datastore and the ProductModel entities are embedded in each entity as a list.
I am wondering if this is an expensive and slow method to store the data. Would it be better to store each ProductModel as a child entity, with a BundleModel as the parent?
In this case, each request for BundleModel would translate into multiple requests for ProductModels. So is the trade-off, one request for a large chunk of data versus multiple requests (about ten or so) for small chunks of data? In terms of writing data, I would then write small chunks separately instead of modifying one big chunk.
What are the ramifications of such a change in terms of cost, speed, and any other parameters?
Thanks!
No, using structured property will be faster and cheaper then using a separate child entities.
The way structured property works is by flattening the structure and automagically creating new properties in the entity for each property in the structure. In your case your BundleModel
entity would get autogenerated properties: product_vals.p_created
, product_vals.p_updated
, etc..
Structured property is better as it only stores one entity, instead of two or more (parent+child). This makes it faster and cheaper. Note that there is no cost per entity size when accessing it.
Note on limitations:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.