Skip to content

Collection::makeTree() hits database for each child #231

@ritterg

Description

@ritterg

I use ->getDescendants()->toTree() to get the whole tree and show it as a hierarchical list of checkboxes.
Up to version 5.1.1 this was one database hit (to get descendants).
select * from termsinner jointerm_closureonterm_closure.descendant=terms.idwhereterm_closure.ancestor= 1 andterm_closure.depth > 0

In version 6 it is now one database hit (to get descendants, same as above) and one database hit for each child
select * from termswhereterms.parent_id= 2 andterms.parent_id is not null

This makes building a larger tree very slow.

The problem seems to be on line 174 of Collection.php:
$result[$parentId]->children->add($item);
which used to be (in 5.1.1, Collection.php line 80)
$result[$parentId]->appendRelation($item->getChildrenRelationIndex(), $item);

Is there a way to get the tree without all these database hits?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions