Site Sections: Satchmo Main | Wiki | Demo Store |

Ticket #202 (new enhancement)

Opened 1 year ago

Last modified 2 months ago

Use Modified Preorder Tree Traversal in Category

Reported by: hkpark Assigned to: chris
Priority: major Milestone:
Component: Application Version:
Keywords: product category mptt recursion Cc:

Description

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: == http://www.sitepoint.com/print/hierarchical-data-database == 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.

Attachments

models.patch.txt (3.4 kB) - added by hkpark on 11/01/07 22:20:02.
product/models.py patch for MPTT
product-models-mptt.diff (3.7 kB) - added by jshaffer on 11/02/07 01:12:21.
product-models-mptt-r3.diff (6.0 kB) - added by hkpark on 11/02/07 05:11:44.
r3 11/02/07 05:09:25 changes

Change History

11/01/07 22:20:02 changed by hkpark

  • attachment models.patch.txt added.

product/models.py patch for MPTT

11/01/07 22:20:52 changed by hkpark

  • type changed from defect to enhancement.

sorry, changing to enhancement

11/02/07 01:12:21 changed by jshaffer

  • attachment product-models-mptt.diff added.

11/02/07 01:17:06 changed by jshaffer

  • summary changed from Added Modified Preorder Tree Traversal to Product Category. Removed recursion to Use Modified Preorder Tree Traversal in Category.
  • milestone set to 0.7.

I've attached a diff with some changes that were necessary to get it to run. However, I'm seeing regressions in the tests. Would you verify that the tests pass and update them as needed?

11/02/07 01:29:00 changed by hkpark

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.

Harry

11/02/07 05:09:25 changed by hkpark

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 tests.py 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.

11/02/07 05:11:44 changed by hkpark

  • attachment product-models-mptt-r3.diff added.

r3 11/02/07 05:09:25 changes

11/02/07 16:46:39 changed by chris

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

11/02/07 18:32:25 changed by hkpark

I'm looking at updating that now.

11/09/07 03:19:35 changed by chris

I found this project which has some code that might be useful - http://code.google.com/p/django-categories/

12/29/07 19:42:19 changed by chris

Another implementation - http://code.google.com/p/django-mptt/

03/22/08 15:16:57 changed by chris

  • milestone deleted.

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

05/30/08 17:42:29 changed by airforce1

08/12/08 14:49:18 changed by add

http://www.salewroughtiron.cn installing metal stair rails Interior stair handrail installing metal stair rails Interior stair handrail exterior baluster Glass wood stainless wrought CONTEMPORARY designs stairways aluminum modern log banister DECK outdoor price posts vinyl curved rails http://www.china-made-door.com.cn door gate http://www.beijing-door.cn wrought CONTEMPORARY designs stairways installing metal stair rails Interior stair handrail exterior baluster Glass wood stainless wrought CONTEMPORARY designs stairways aluminum modern log banister DECK outdoor price posts vinyl curved rails http://www.hebei-railings.cn aluminum modern log banister DECK outdoor price installing metal stair rails Interior stair handrail exterior baluster Glass wood stainless wrought CONTEMPORARY designs stairways aluminum modern log banister DECK outdoor price posts vinyl curved rails posts vinyl curved rails

09/12/08 06:30:43 changed by china

china tour Apparel shoes bags Kitchen Food and Wine Furniture) Flowers and Gifts Wall Art Computer Components

I still prefer a wiki like approach since the php (or mysql) docs are very cluttered when you have to take their comments in account. On the other hand they are professionally maintained imho, since they are *much* better than KDE documentation. KDE is by far larger and has so many different apps, which need screenshots and end user not dev/api docs, that more help is needed as long as the devs prefer to code than to write nice docs. And it is their choice to some degree imo. Technically interested but non-dev end users, which are plenty out there, are the users of and the best contributers to the docs, since they know what to write about. And they are certainly more than devs