Selaa lähdekoodia

Optimization of SQL queries: fixed!

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2486 a333f486-631f-4898-b8df-5754b55c2be0
romainq 12 vuotta sitten
vanhempi
commit
e22bed86b0
2 muutettua tiedostoa jossa 13 lisäystä ja 15 poistoa
  1. 1 1
      core/config.class.inc.php
  2. 12 14
      core/metamodel.class.php

+ 1 - 1
core/config.class.inc.php

@@ -145,7 +145,7 @@ class Config
 			'type' => 'bool',
 			'description' => 'For developpers: format the SQL queries for human analysis',
 			'default' => false,
-			'value' => true,
+			'value' => false,
 			'source_of_value' => '',
 			'show_in_conf_sample' => false,
 		),

+ 12 - 14
core/metamodel.class.php

@@ -2138,7 +2138,6 @@ abstract class MetaModel
 		}
 
 		$oSelect = self::MakeSelectStructure($oFilter, $aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart, $bGetCount);
-		$oSelect = unserialize(serialize($oSelect));
 
 		$aScalarArgs = array_merge(self::PrepareQueryArguments($aArgs), $oFilter->GetInternalParams());
 		try
@@ -2245,8 +2244,8 @@ abstract class MetaModel
 			if (array_key_exists($sOqlId, self::$m_aQueryStructCache))
 			{
 				// hit!
-				$oSelect = clone self::$m_aQueryStructCache[$sOqlId];
-				// Note: cloning is not enough... should be replaced by unserialize(serialize()) !!!
+				$oSelect = unserialize(serialize(self::$m_aQueryStructCache[$sOqlId]));
+				// Note: cloning is not enough because the subtree is made of objects
 			}
 			elseif (self::$m_bUseAPCCache)
 			{
@@ -2284,6 +2283,16 @@ abstract class MetaModel
 				$oSelect->SetSelect($oBuild->m_oQBExpressions->GetSelect());
 			}
 
+			if (self::$m_bOptimizeQueries)
+			{
+				if ($bGetCount)
+				{
+					// Simplify the query if just getting the count
+					$oSelect->SetSelect(array());
+				}
+				$oSelect->OptimizeJoins();
+			}
+
 			$oKPI->ComputeStats('MakeQuery (select)', $sOqlQuery);
 
 			if (self::$m_bQueryCacheEnabled)
@@ -2297,17 +2306,6 @@ abstract class MetaModel
 
 				self::$m_aQueryStructCache[$sOqlId] = clone $oSelect;
 			}
-
-			if (self::$m_bOptimizeQueries)
-			{
-				// Simplify the query if just getting the count
-				//
-				if ($bGetCount)
-				{
-					$oSelect->SetSelect(array());
-				}
-				$oSelect->OptimizeJoins();
-			}
 		}
 
 		// Join to an additional table, if required...