Disabling MPTT for a field

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.

Just for reference, you can also disable the left and right properties defined on a dependency module using __setup__:

def __setup__(cls):
    cls.field.left = None
    cls.field.right = None

And also for the record there is Issue 10623: Rethink MPTT threshold between update and rebuild - Tryton issue tracker and Issue 7177: Alternative to MPTT using stored path - Tryton issue tracker to improve the situation.

Is there a way to judge the consequences of disabling left and right on project.work? Will this break functionality, or just remove an optimization?

TBH, project.work is extremely over-engineered compared to what we use it for. We aren’t using timesheets for our projects.

What a difference disabling MPTT makes!

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.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.