Use Modified Preorder Tree Traversal in Category

Create issue
Issue #202 wontfix
Former user created an issue

I've added MPTT to the product category and removed the recursion. Although I did leave in the old private function names in case some people were using them on the sly.

Here's a link to an article about the pros and cons of it: == == Storing Hierarchical Data in a Database

I thought Satchmo shouldn't go without some method of retrieving rows with a single query. I'm working with some larger category trees than the sample store data and thought this might speed things up since the category tree is frequently used.

Now getting children and getting parents is a single query, no recursing down the tree and building a large function stack and fetching the items one by one.

Reported by hkpark

Comments (11)

  1. Former user Account Deleted

    Okay I've updated the changes again. I noticed some errors in my initial version. It would only allow for one root in all the categories, but the demo store has 3 separate root categories: Books, Shirts, Software. So I've updated the class to allow for multiple roots. The data is correct in the admin for the demo store. It wasn't in the first iteration.

    Included comments about the purposely misspelled left and right: lft, rght

    Also noticed that the test cases assume that you will be able to create an infinite loop with the Category class. The class with this patch won't let you make an infinite loop because it will immediately reorder the tree on save. The subsequent tests fail because they need the infinite loop to be in the database.

    I can add some more tests to that just give more straightforward category structures and makes sure the data comes back correct. My thoughts were to add multiple root categories like in the demo store, make sure the parents are correct, the children come back correct. I've spent one day with the class so I was hoping to work with someone to ensure I'm testing for the right data.

  2. Former user Account Deleted

    left and right are keywords in SQL, so you can't use them for field names, hence the lft and rght. Maybe there should be a comment in there explaining that.

    I'll take a look at changes besides those and see how to run these tests.


  3. Chris Moffitt repo owner
    • removed milestone

    I'm moving out of the next release. This might be useful but it's not a requirement at this time.

  4. Chris Moffitt repo owner

    Do we also need to look at modifying the template tag to not recurse?

  5. Log in to comment