I have a design where a ModelSQL has a recursive relation, and both the parent and child are created in the same transaction. This “nested” creation that causes ModelSQL._rebuild_tree to be called, leading to a very long transaction.
I have no need for MPTT on this recursive field, and I am wondering if there is a recommended idiom for disabling it.
The MPTT is only used if you declare the left and right attributes.
If you set such values of the field to None (which is the default value) tryton won’t compute the MPTT which will result in a faster transation
Thank you. I am dealing with customization of project.work, so left and right are set in the inherited module. But Cedric has explained to me why disabling MPTT might be a bad idea.
We have been having trouble with (a) database migration time, and (b) the time it takes to create batches of Works. Disabling MPTT at the project module level reduces the migration time from numerous hours to 4 minutes[1]! It also improves batch creation.
Of course, if removing MPTT breaks things (as opposed to just removing an optimization), then that is a problem. If it doesn’t break anything, then I am very interested in disabling it, with the knowledge that I could re-enable it in the future using _rebuild_tree (though that would be unlikely).
[1] To be fair, there is also another optimization that is cutting out some time, but most of the change is MPTT.