Re: bpContents 1.0 Alpha 1 – Member, Group and Blog Tagging for BuddyPress
Oh. Before anyone publicly complains, no, there isn’t any pagination included in alpha 1’s directories. I’m totally ignoring it on purpose. All the code is there ready to take advantage of it but I purposely didn’t implement it.
bpc uses a mechanism called Modifed Pre-Order Tree Traversal (MPTT) that was specifically designed to track tree like structures in SQL tables. I need to find out if that part of the core is working properly. I had no intention of introducing another complexity down at the SQL level right now. As far as I can tell the MPTT implementation is stable.
I swore I wasn’t gonna document this for programmers yet but I guess it wouldn’t hurt to talk about MPTT now.
When you look at the properties for a node, in the class OCI_Node, you’ll notice two vars $this->lft and $this->rgt. These are MPTT specfic vars that represent the parent/child relationships of all nodes in the tree. . See these for info about MPTT:
http://www.sitepoint.com/article/hierarchical-data-database/
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
http://www.dbmsmag.com/9604d06.html
A simple node insert operation in the tree has a good chance of changing 50% of the lft/rgt values in the entire tree.
Any sql operation that changes these values must:
1) lock the table
2) get the node and it’s valid lft/rgt values
3) do the operation
4) unlock the tree
The only reliable property for a node in the tree is the $this->id which is the record id in the table.
The boys and girls at wp are investigating MPTT right now for a future version of wp. I can’t wait around until they get to that so I’ve implemented this in bpc. It’s a natural for this kind of project and has many advantages.