瀏覽代碼

Performance enhancement for impact analysis: avoid looping in the recursion.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2505 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 12 年之前
父節點
當前提交
8bf3f984a4
共有 1 個文件被更改,包括 16 次插入1 次删除
  1. 16 1
      pages/xml.navigator.php

+ 16 - 1
pages/xml.navigator.php

@@ -55,6 +55,8 @@ function AddNodeDetails(&$oNode, $oObj)
 	$oNode->SetAttribute('zlist', implode(',', $aLabels));
 }
 
+$G_aCachedObjects = array();
+
 /**
  * Get the related objects through the given relation, output in XML
  * @param DBObject $oObj The current object
@@ -62,10 +64,23 @@ function AddNodeDetails(&$oNode, $oObj)
  */
 function GetRelatedObjectsAsXml(DBObject $oObj, $sRelationName, &$oLinks, &$oXmlDoc, &$oXmlNode, $iDepth = 0, $aExcludedClasses)
 {
+	global $G_aCachedObjects;
 	$aResults = array();
 	$bAddLinks = false;
-	$oObj->GetRelatedObjects($sRelationName, 1 /* iMaxDepth */, $aResults);
+
 	if ($iDepth > MAX_RECURSION_DEPTH) return;
+
+	$sIdxKey = get_class($oObj).':'.$oObj->GetKey();
+	if (!array_key_exists($sIdxKey, $G_aCachedObjects))
+	{
+		$oObj->GetRelatedObjects($sRelationName, 1 /* iMaxDepth */, $aResults);
+		$G_aCachedObjects[$sIdxKey] = true;
+	}
+	else
+	{
+		return;
+		//$aResults = $G_aCachedObjects[$sIdxKey];
+	}
 	
 	foreach($aResults as $sRelatedClass => $aObjects)
 	{