mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-08-22 23:05:18 -04:00
Add unittest and caching to ORM_MTPP::descendants_count
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user