Help: Dynamic NodeGroup Updates: Managing Link Movements with Socket Name

I am working on a certain Add-On, part of which is the dynamic creation of Node groups.

I use the following code to update the NodeTree of each Node when the underlying NodeTree is updated.

         for node in self.nodes:
             node.node_tree = self.node_tree

The thing is when I update the NodeTree, new output sockets should sometimes be created between the old ones, and when I do that, the old links that were connected to the old outputs stay in place. (Although they should go down with the outputs.)
Is there a way to make them move together with the output sockets?

I think it would be wise to do it socket name based, because in my case each socket has a unique name, but any other idea would be welcome.

By the way, I would prefer if the answers you offer do not include the use of the NodeTree where the connected nodes are located, since it will be too heavy for performance to search for it for each node.