Преглед изворни кода

Optimization: improved the OQL cache:
- take benefit of the APC cache (if present)
- memory indexation could fail in case of long queries (query id based on a md5)
- added kpi measure on the OQL parsing

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3635 a333f486-631f-4898-b8df-5754b55c2be0

romainq пре 10 година
родитељ
комит
7645488c0d
1 измењених фајлова са 44 додато и 17 уклоњено
  1. 44 17
      core/dbsearch.class.php

+ 44 - 17
core/dbsearch.class.php

@@ -178,36 +178,63 @@ abstract class DBSearch
 		if (empty($sQuery)) return null;
 
 		// Query caching
+		$sQueryId = md5($sQuery);
 		$bOQLCacheEnabled = true;
-		if ($bOQLCacheEnabled && array_key_exists($sQuery, self::$m_aOQLQueries))
+		if ($bOQLCacheEnabled)
 		{
-			// hit!
-			$oClone = self::$m_aOQLQueries[$sQuery]->DeepClone();
-			if (!is_null($aParams))
+			if (array_key_exists($sQueryId, self::$m_aOQLQueries))
 			{
-				$oClone->SetInternalParams($aParams);
+				// hit!
+				$oResultFilter = self::$m_aOQLQueries[$sQueryId]->DeepClone();
+			}
+			elseif (self::$m_bUseAPCCache)
+			{
+				// Note: For versions of APC older than 3.0.17, fetch() accepts only one parameter
+				//
+				$sAPCCacheId = 'itop-'.MetaModel::GetEnvironmentId().'-dbsearch-cache-'.$sQueryId;
+				$oKPI = new ExecutionKPI();
+				$result = apc_fetch($sAPCCacheId);
+				$oKPI->ComputeStats('Search APC (fetch)', $sQuery);
+	
+				if (is_object($result))
+				{
+					$oResultFilter = $result;
+					self::$m_aOQLQueries[$sQueryId] = $oResultFilter->DeepClone();
+				}
 			}
-			return $oClone;
 		}
 
-		$oOql = new OqlInterpreter($sQuery);
-		$oOqlQuery = $oOql->ParseQuery();
+		if (!isset($oResultFilter))
+		{
+			$oKPI = new ExecutionKPI();
+
+			$oOql = new OqlInterpreter($sQuery);
+			$oOqlQuery = $oOql->ParseQuery();
+	
+			$oMetaModel = new ModelReflectionRuntime();
+			$oOqlQuery->Check($oMetaModel, $sQuery); // Exceptions thrown in case of issue
+	
+			$oResultFilter = $oOqlQuery->ToDBSearch($sQuery);
 
-		$oMetaModel = new ModelReflectionRuntime();
-		$oOqlQuery->Check($oMetaModel, $sQuery); // Exceptions thrown in case of issue
+			$oKPI->ComputeStats('Parse OQL', $sQuery);
+	
+			if ($bOQLCacheEnabled)
+			{
+				self::$m_aOQLQueries[$sQueryId] = $oResultFilter->DeepClone();
 
-		$oResultFilter = $oOqlQuery->ToDBSearch($sQuery);
+				if (self::$m_bUseAPCCache)
+				{
+					$oKPI = new ExecutionKPI();
+					apc_store($sAPCCacheId, $oResultFilter, self::$m_iQueryCacheTTL);
+					$oKPI->ComputeStats('Search APC (store)', $sQueryId);
+				}
+			}
+		}
 
 		if (!is_null($aParams))
 		{
 			$oResultFilter->SetInternalParams($aParams);
 		}
-
-		if ($bOQLCacheEnabled)
-		{
-			self::$m_aOQLQueries[$sQuery] = $oResultFilter->DeepClone();
-		}
-
 		return $oResultFilter;
 	}