laravel-nestedset
laravel-nestedset copied to clipboard
400+ queries to fetch all descendants of root
I have a large tree of nodes containing several root nodes with many children in each. When trying to fetch all the children of one of the root nodes with a simple query:
$children = Group::descendantsAndSelf($root_id);
then the result is 400+ queries against the database.
Is this by design?
I'm using laravel-nestedset version ^5.0
That doesn't sound right. A single query should be enough to fetch an entire tree or subtree.
Debugged this a bit further. The 400 queries comes from the function getNodeData
in Kalnoy\Nestedset\QueryBuilder.php
:
$data = $query->first([ $this->model->getLftName(),
$this->model->getRgtName() ]);
Any solution for this?
@tiagofcp It doesnt seem like there's any interest in fixing this bug, my workaround was to query the left and right properties of the root group, and put them in a native query. Looks really ugly but gets the job done in 1 query.