From 26fa2ba2c53c40ab1bb852d44ca8aad04739ac48 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 22 Aug 2009 12:56:11 +1000 Subject: [PATCH] Only sort children after reading additional entries --- lib/AJAXTree.php | 4 +--- lib/Tree.php | 4 ++++ lib/TreeItem.php | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/lib/AJAXTree.php b/lib/AJAXTree.php index 051342b..dac0288 100644 --- a/lib/AJAXTree.php +++ b/lib/AJAXTree.php @@ -147,10 +147,8 @@ class AJAXTree extends HTMLTree { debug_log('Entered (%%)',33,0,__FILE__,__LINE__,__METHOD__,$fargs); $children = array(); - $pchildren = $parent_entry->getChildren(); - usort($pchildren,'pla_compare_dns'); - foreach ($pchildren as $child) { + foreach ($parent_entry->getChildren() as $child) { if (! $this->getEntry($child)) $this->addEntry($child); diff --git a/lib/Tree.php b/lib/Tree.php index 55bba8f..b3efcf9 100644 --- a/lib/Tree.php +++ b/lib/Tree.php @@ -301,6 +301,8 @@ abstract class Tree { if ($nolimit) @set_time_limit($_SESSION[APPCONFIG]->getValue('search','time_limit')); + $this->entries[$dnlower]->readingChildren(true); + foreach ($ldap['children'] as $child) { if (DEBUG_ENABLED) debug_log('Adding (%s)',64,0,__FILE__,__LINE__,__METHOD__,$child); @@ -309,6 +311,8 @@ abstract class Tree { $this->entries[$dnlower]->addChild($child); } + $this->entries[$dnlower]->readingChildren(false); + if (count($this->entries[$dnlower]->getChildren()) == $ldap['child_limit']) $this->entries[$dnlower]->setSizeLimited(); else diff --git a/lib/TreeItem.php b/lib/TreeItem.php index 840854d..61cee56 100644 --- a/lib/TreeItem.php +++ b/lib/TreeItem.php @@ -33,6 +33,10 @@ class TreeItem { private $size_limited = true; # Last template used to edit this entry private $template = null; + # Do we need to sort the children + private $childsort = true; + # Are we reading the children + private $reading_children = false; public function __construct($server_id,$dn) { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) @@ -115,9 +119,38 @@ class TreeItem { if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->children); + if ($this->childsort && ! $this->reading_children) { + usort($this->children,'pla_compare_dns'); + $this->childsort = false; + } + return $this->children; } + public function readingChildren($bool) { + $this->reading_children = $bool; + } + + /** + * Do the children require resorting + */ + public function isChildSorted() { + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) + debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs,$this->childsort); + + return $this->childsort; + } + + /** + * Mark the children as sorted + */ + public function childSorted() { + if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) + debug_log('Entered (%%)',33,1,__FILE__,__LINE__,__METHOD__,$fargs); + + $this->childsort = false; + } + /** * Add a child to this DN entry. * @@ -131,6 +164,7 @@ class TreeItem { return; array_push($this->children,$dn); + $this->childsort = true; } /**