mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 19:18:44 +02:00
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 SVN:trunk[3635]
This commit is contained in:
@@ -178,36 +178,63 @@ abstract class DBSearch
|
|||||||
if (empty($sQuery)) return null;
|
if (empty($sQuery)) return null;
|
||||||
|
|
||||||
// Query caching
|
// Query caching
|
||||||
|
$sQueryId = md5($sQuery);
|
||||||
$bOQLCacheEnabled = true;
|
$bOQLCacheEnabled = true;
|
||||||
if ($bOQLCacheEnabled && array_key_exists($sQuery, self::$m_aOQLQueries))
|
if ($bOQLCacheEnabled)
|
||||||
{
|
{
|
||||||
// hit!
|
if (array_key_exists($sQueryId, self::$m_aOQLQueries))
|
||||||
$oClone = self::$m_aOQLQueries[$sQuery]->DeepClone();
|
|
||||||
if (!is_null($aParams))
|
|
||||||
{
|
{
|
||||||
$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);
|
if (!isset($oResultFilter))
|
||||||
$oOqlQuery = $oOql->ParseQuery();
|
{
|
||||||
|
$oKPI = new ExecutionKPI();
|
||||||
|
|
||||||
$oMetaModel = new ModelReflectionRuntime();
|
$oOql = new OqlInterpreter($sQuery);
|
||||||
$oOqlQuery->Check($oMetaModel, $sQuery); // Exceptions thrown in case of issue
|
$oOqlQuery = $oOql->ParseQuery();
|
||||||
|
|
||||||
|
$oMetaModel = new ModelReflectionRuntime();
|
||||||
|
$oOqlQuery->Check($oMetaModel, $sQuery); // Exceptions thrown in case of issue
|
||||||
|
|
||||||
|
$oResultFilter = $oOqlQuery->ToDBSearch($sQuery);
|
||||||
|
|
||||||
$oResultFilter = $oOqlQuery->ToDBSearch($sQuery);
|
$oKPI->ComputeStats('Parse OQL', $sQuery);
|
||||||
|
|
||||||
|
if ($bOQLCacheEnabled)
|
||||||
|
{
|
||||||
|
self::$m_aOQLQueries[$sQueryId] = $oResultFilter->DeepClone();
|
||||||
|
|
||||||
|
if (self::$m_bUseAPCCache)
|
||||||
|
{
|
||||||
|
$oKPI = new ExecutionKPI();
|
||||||
|
apc_store($sAPCCacheId, $oResultFilter, self::$m_iQueryCacheTTL);
|
||||||
|
$oKPI->ComputeStats('Search APC (store)', $sQueryId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_null($aParams))
|
if (!is_null($aParams))
|
||||||
{
|
{
|
||||||
$oResultFilter->SetInternalParams($aParams);
|
$oResultFilter->SetInternalParams($aParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bOQLCacheEnabled)
|
|
||||||
{
|
|
||||||
self::$m_aOQLQueries[$sQuery] = $oResultFilter->DeepClone();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $oResultFilter;
|
return $oResultFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user