-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v4.5.2
Feature type
Change to existing functionality
Proposed functionality
Replace the django-mptt library with Postgresql tree.
A wrapper would need to be created around ltree using the same API as MPTT to be able to pretty much be a drop-in replacement. add_related_count function would need special consideration. This would involve some raw SQL code.
Postgresql handles the basics of the path, but does not handle moving of nodes and updating the tree so triggers would need to be written for handling that. These would be fairly lightweight and self-contained.
There are a couple projects for integrating django and ltree, but they have minimal functionality and the code is fairly small so it just makes sense to write it from scratch.
I wrote a preliminary proof-of-concept and it passes all the netbox tests and some spot tests looked good, but would need more thorough testing and also tiggers to update the tree as the current method uses a slow python function.
Use case
django-mptt is no longer maintained. Additionally, this presents an opportunity to adopt a recursive nesting solution that may prove to be more performant and/or scalable than MPTT. This idea was originally raised in #11421.
Note: There is a separate issue #12552 to Replace MPTT - this is a more specific ticket to track the viability of ltree.
Database changes
MPTT library includes fields to track the inheritance path of the object via mixins, all these models would need to have migrations to convert the path to the new ltree path. Using this involves some raw SQL code and use of some triggers (probably via pgtrigger). but is fairly lightweight and self-contained.
External dependencies
Potentially django-pgtrigger We could do the trigger code without this, but this would make it more maintainable.