1

How to traverse a tree of MP_Node (django-treebeard) categories and display effectively with lease amount of queries? I tried looking the docs but I see the queries number increasing with more categories.

  1. Is there a method to limit the number of queries to display a menu like amazon.com and get all the categories in an optimized manner?
  2. I see that dump_bulk() api in treebeard gets all the categories in a single query. Is it advisable to use it? If not why? Where is its practical usage?
  3. A sample code using twitter-bootstrap nav menu would be appreciated.

I'm looking to reduce the number of queries. Answer with explanation with least number of queries will be accepted.

Bharathwaaj
  • 2,627
  • 2
  • 22
  • 35

1 Answers1

0

I chose django-mptt in lieu of Treebeard. It's much more simple, and uses only one tree management methodology (MPTT, hence the name). See this function (disclaimer, I submitted a patch which rewrote this function to be more optimized) - it caches an entire tree below a given node, allowing you to go up and down the tree as much as you want (e.g., node.get_children(), node.parent, etc.), without running any more queries. In other words, it's ideal for doing exactly what you're wanting to do.

orokusaki
  • 55,146
  • 59
  • 179
  • 257