diff options
Diffstat (limited to 'core/libraries')
-rw-r--r-- | core/libraries/ORM_MPTT.php | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/core/libraries/ORM_MPTT.php b/core/libraries/ORM_MPTT.php index 5cdf9c02..c9c29805 100644 --- a/core/libraries/ORM_MPTT.php +++ b/core/libraries/ORM_MPTT.php @@ -37,6 +37,7 @@ class ORM_MPTT_Core extends ORM { private $parents = null; private $children = null; private $children_count = null; + private $descendants_count = array(); function __construct($id=null) { parent::__construct($id); @@ -165,19 +166,18 @@ class ORM_MPTT_Core extends ORM { * @return integer child count */ function descendants_count($type=null) { - // @todo create a unit test - // @todo set up caching in an array;; using type=all allows us to cache as decendents[$type] - $this->where("left >=", $this->left) - ->where("right <=", $this->right); - if ($type) { - $this->where("type", $type); + if (!isset($this->descendants_count[$type])) { + $this->where("left >", $this->left) + ->where("right <=", $this->right); + if ($type) { + $this->where("type", $type); + } + $this->descendants_count[$type] = $this->count_all(); } - // @todo does it make sense to order it before counting? - return $this->count_all(); + return $this->descendants_count[$type]; } - /** * @see ORM::reload */ |