django-mptt/django-mptt — pull request #201 by craigds (2012-08-03 04:25:14+00:00)
Title: Delayed/partial updates #69

re issue #69

1. minimum python version is now 2.5
2. Added a `TreeManager.disable_mptt_updates()` contextmanager for doing large bulk updates spanning a large part of the db table. Callers should follow it with a call to TreeManager.rebuild(), and wrap both in a transaction block.
3. Added a `TreeManager.delay_mptt_updates()` contextmanager for doing bulk updates that don't span most of the tree. This is best for updates in a localised area of the db table, especially if all the updates happen in a single tree and the rest of the forest is left untouched. No subsequent rebuild is necessary.

Both new contextmanagers are for power users only. They both cause database inconsistencies. In the case of `delay_mptt_updates`, those inconsistencies are temporary and will be fixed at the end of the context block.

`delay_mptt_updates` does a *partial rebuild* of the modified trees (not the whole table). If used indiscriminately, this can actually be much slower than just letting the updates occur when they're required. The worst case occurs when each tree in the database is modified just once. That results in a full rebuild of the table. Future optimisations could be made later in that regard.