diff --git a/core/model/Hierarchy.php b/core/model/Hierarchy.php index 3bdd6bf83..4a143e365 100755 --- a/core/model/Hierarchy.php +++ b/core/model/Hierarchy.php @@ -100,6 +100,10 @@ class Hierarchy extends DataObjectDecorator { // foreach can't handle an ever-growing $nodes list while(list($id, $node) = each($this->markedNodes)) { + // Inspect the number of potential nodes to mark - if its more than the minimum count, + // don't query them in the first place to inspect further marking state in-memory + if((sizeof($this->markedNodes) + $node->$numChildrenMethod()) >= $minNodeCount) break; + $this->markChildren($node, $context, $childrenMethod, $numChildrenMethod); if($minNodeCount && sizeof($this->markedNodes) >= $minNodeCount) { break;