During the development of
MDL-57292 was detected the process of mapping children competencies to parents is very expensive and could be optimised.
At the moment the code is looping over $this->flat, and checking each value for a parentage match, it then calls add_children recursively for each child.
Essentially this means that you have an n^2 loop over each component.
Since we're only comparing the parentidnumber, we can do this easily and more efficiently by:
- using array_map to fetch the parentidnumber for each row in the file (stored by index)
- use array_keys with it's $search param to find any indexes which use that parentidnumber
- loop over just those rows in the file
This means that we only ever process n loops (instead of n^2) which is much more efficient.