Question

I am considering ways of organizing data for my application.

One data model I am considering would entail having entities where each entity could contain up to roughly 100 repeated StructuredProperties. The StructuredProperties would be mostly read and updated only very infrequently. My question is - if I update any of those StructuredProperties, will the entire entity get deleted from Memcache and will the entire entity be reread from the ndb? Or is it just the single StructuredProperty that will get reread? Is this any different with LocalStructuredProperty?

More generally, how are StructuredProperties organized internally? In situations where I could use multiple Float or Int properties - and I am using a StructuredProperty instead just to make my model more readable - is this a bad idea? If I am reading an entity with 100 StructuredProperties will I have to make 100 rpc calls or are the properties retrieved in bulk as part of the original entity?

Was it helpful?

Solution

StructuredPropertys belong to the entity that contains them - so your assumption that updating a single StructuredProperty will invalidate the memcache is correct.

LocalStructuredProperty is the same behavior - the advantage however is that each property on a LocalStructuredProperty is obfuscated into a binary storage - the datastore has no idea about the structure of a LocalStructuredProperty. (There is probably a deserialization computational cost attributed to these properties - but that depends a lot on the amount of data they contain, I imagine.)

To contrast, StructuredProperty actually makes its child properties available for Query indexing in most cases - allowing you to perform complicated lookups.

Keep in mind - you should be calling put() for the containing entity, not for each StructuredProperty or LocalStructuredProperty - so you should be seeing a single RPC call for updating that parent entity - regardless of the number of repeated properties exist.

I would advise using StructuredProperty that contain ndb.IntegerProperty(repeated=True), rather than making 'parallel lists' of integers and floats - that adds more complexity to your python model, and is exactly the behavior that ndb.StructuredProperty strives to replace.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top