google app engine - Tree structures in a nosql database -


I am developing an application for Google App Engine which uses BigTable for its datastore.

This application about writing a collaborative story is a very simple hobby project which I am working for fun. This is an open source and you can see it here:

The idea is that any paragraph can be written, after which it should be confirmed by two other people. The story can be divided into any paragraph, so that the second version of the story can continue in the other direction.

Imagine the structure of the following tree:

Each number will be a paragraph. I want to be able to select all paragraphs in every unique story line. Actually, these unique story lines are (2, 7, 2); (2, 7, 6, 5); (2, 7, 6, 11) and (2, 5, 9, 4). Ignore that the node "2" appears twice, I've taken a tree structure diagram from Wikipedia.

I have also created a diagram of the proposed solution:

How can I set structure for both writing works, but the most important thing to read?

Methods of representing trees in the database; Each of them has its own professional and opposition, the most common here is:

  • , where each node stores its parent ID.
  • , which is described by Kir, is also the method used by unit groups in the API engine (e.g., basic bodies).
  • , where there is a 'left' and 'true' id in each node, such as all the child nodes are included in that category.
  • Stability lists grow with a root id.

Each of these has its own advantages and disadvantages. Stability list is simple and cheap to update, but multiple queries are needed to get sub-recovery (one for each parent node). Enhanced adjacent lists made it possible to retrieve the whole tree by storing the root node's ID in each record.

The physical path is easy to implement and is affordable for updating, and uncontrolled sub-years are allowed to query, but increases the upper part for deep trees.

Nested sets are difficult to apply, and each time you do an insertion, on average, half nodes need to be updated. They allow you to ask arbitrary sub-slabs, without increasing length of the physical path of length.

In your specific case, it seems that you do not really need a tree structure: each story, although it can be original, stand alone. What I suggest is a 'story' model, in which the key of its paragraph (exemplified, in Python includes a DB. Listproperty (DBKA)). To render a story, you bring the story, then fetch a batch for all the paragraphs. To share the story, just copy the story entry - leave paragraphs references unchanged.


Comments