Better threshold between rebuild and update MPTT
For now, the threshold is: len(ids) < count / 4
This number comes from the number of queries each method will generate:
rebuild: 2 queries per node -> 2*count
update: 8 queries per new node -> 8*len(ids)
But the number of query is not a very good measure of the cost because some queries in 'update' could potentially write on all nodes. So indeed we should compute the number of nodes modified:
rebuild: 1 write and 1 select on each node-> 2*count
update: (1 write + 3 select + 2 write on average ½ all nodes + 1 write on child of id) on each ids
The ½ all nodes come from medium between all nodes (if inserted at the beginning) and 0 nodes (if inserted at the end).
So the threshold should be expressed as:
2*count < (4 + 2*count/2 + 1 * x) * len(ids)
2*count < (4 + count + x) * len(ids)
I think we can remove from the right: x because we can not evaluate it and it normally quite smaller than count.
we can also remove (4 * lend(ids)) compare to count because it will be the same on very small tree where the difference between rebuild or update doesn't matter.
So the threshold become:
2*count < count * len(ids)
2 < len(ids)
So we must do an rebuild as far as two records are created/modified.