Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hierarchy in Google App Engine NDB

I'm trying to store a hierarchy in NDB and I'm confused about if I should use just the 'parent' parameter while constructing the keys to new entities or should I include an extra property in my models to hold the parent key?

like image 731
0xcurb Avatar asked Dec 30 '25 01:12

0xcurb


1 Answers

If you use the ancestor in the key you will create a big entity group (assuming a single root to the tree/hierarchy) which may in fact not be what you want from a write performance point of view. Also a deep hierarchy can mean very big keys.

If you want to move nodes around using ancestor keys, you have to delete and recreate the entire child hierarchy of keys, where as storing the parent in the node (or the children keys in the parent) means you just store different keys in properties.

If you normally walk down the hierarchy (say url traversal) you may find it more efficient to just store the childrens keys in a list in the parent, assuming each level is not going to have too many immediate children, as well as storing the parent key in the child.

I would examine your actual requirements in detail before deciding which way to go.

like image 56
Tim Hoffman Avatar answered Jan 01 '26 15:01

Tim Hoffman