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:
Romain Quetiez
2015-07-09 14:37:29 +00:00
parent a6b74d6538
commit df9f25dc3c

View File

@@ -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();
$oMetaModel = new ModelReflectionRuntime();
$oOqlQuery->Check($oMetaModel, $sQuery); // Exceptions thrown in case of issue
$oOql = new OqlInterpreter($sQuery);
$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))
{
$oResultFilter->SetInternalParams($aParams);
}
if ($bOQLCacheEnabled)
{
self::$m_aOQLQueries[$sQuery] = $oResultFilter->DeepClone();
}
return $oResultFilter;
}