mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°2272 - OQL performance (unit tests)
This commit is contained in:
@@ -1277,6 +1277,23 @@ abstract class DBSearch
|
||||
{
|
||||
$aQueryData['oql'] = $sOql;
|
||||
unset($aQueryData['filter']);
|
||||
if (!empty($aAttToLoad))
|
||||
{
|
||||
$aAttToLoadNames = array();
|
||||
foreach ($aAttToLoad as $sClass => $aAttributes)
|
||||
{
|
||||
$aAttToLoadNames[$sClass] = array();
|
||||
foreach ($aAttributes as $sAttCode => $oAttDef)
|
||||
{
|
||||
$aAttToLoadNames[$sClass][] = $sAttCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$aAttToLoadNames = null;
|
||||
}
|
||||
$aQueryData['att_to_load'] = $aAttToLoadNames;
|
||||
|
||||
$hLogFile = @fopen(APPROOT.'log/oql_records.txt', 'a');
|
||||
if ($hLogFile !== false)
|
||||
|
||||
@@ -105,8 +105,8 @@ if ($oOQLHandle) {
|
||||
$iCount++;
|
||||
$sOrderBy = ConvertArray($aRecord['order_by']);
|
||||
$sArgs = ConvertArray($aRecord['args']);
|
||||
$sGroupByExpr = ConvertArray($aRecord['group_by_expr']);
|
||||
$sSelectExpr = ConvertArray($aRecord['select_expr']);
|
||||
$sGroupByExpr = ConvertArray($aRecord['group_by_expr'], true);
|
||||
$sSelectExpr = ConvertArray($aRecord['select_expr'], true);
|
||||
if ($aRecord['exclude_null_values'])
|
||||
{
|
||||
$bExcludeNullValues = 'true';
|
||||
@@ -134,7 +134,7 @@ if ($oOQLHandle) {
|
||||
|
||||
echo "<br>File '$sTestFile' generated with ".($iCount-1000)." entries (from $iRead captured OQL).\n";
|
||||
|
||||
function ConvertArray($aArray)
|
||||
function ConvertArray($aArray, $bB64Encode = false)
|
||||
{
|
||||
if (is_null($aArray))
|
||||
{
|
||||
@@ -146,5 +146,9 @@ function ConvertArray($aArray)
|
||||
return 'array()';
|
||||
}
|
||||
|
||||
return 'unserialize(base64_decode(\''.base64_encode(serialize($aArray)).'\'))';
|
||||
if ($bB64Encode)
|
||||
{
|
||||
return 'unserialize(base64_decode(\''.base64_encode(serialize($aArray)).'\'))';
|
||||
}
|
||||
return 'unserialize(\''.serialize($aArray).'\')';
|
||||
}
|
||||
@@ -238,8 +238,31 @@ class OQLToSQLTest extends ItopDataTestCase
|
||||
* @throws \MissingQueryArgument
|
||||
* @throws \OQLException
|
||||
*/
|
||||
private function OQLSelectRunner($sOQL, $aOrderBy = array(), $aArgs = array(), $aAttToLoad = null, $aExtendedDataSpec = null, $iLimitCount = 20, $iLimitStart = 0)
|
||||
private function OQLSelectRunner($sOQL, $aOrderBy = array(), $aArgs = array(), $aAttToLoadNames = null, $aExtendedDataSpec = null, $iLimitCount = 20, $iLimitStart = 0)
|
||||
{
|
||||
if (is_null($aAttToLoadNames))
|
||||
{
|
||||
$aAttToLoad = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
$aAttToLoad = array();
|
||||
foreach ($aAttToLoadNames as $sClass => $aAttCodes)
|
||||
{
|
||||
$aAttToLoad[$sClass] = array();
|
||||
foreach ($aAttCodes as $sAttCode)
|
||||
{
|
||||
if (!empty($sAttCode))
|
||||
{
|
||||
if (MetaModel::IsValidAttCode($sClass, $sAttCode))
|
||||
{
|
||||
$aAttToLoad[$sClass][$sAttCode] = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$oSearch = DBSearch::FromOQL($sOQL);
|
||||
|
||||
$sSQLCount = $oSearch->MakeSelectQuery($aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, 0, 0, true);
|
||||
@@ -343,12 +366,12 @@ class OQLToSQLTest extends ItopDataTestCase
|
||||
|
||||
$aAttToLoad150 = array(
|
||||
'WebServer' => array(
|
||||
'business_criticity' => MetaModel::GetAttributeDef('WebServer', 'business_criticity'),
|
||||
'description' => MetaModel::GetAttributeDef('WebServer', 'description'),
|
||||
'name' => MetaModel::GetAttributeDef('WebServer', 'name'),
|
||||
'friendlyname' => MetaModel::GetAttributeDef('WebServer', 'friendlyname'),
|
||||
'obsolescence_flag' => MetaModel::GetAttributeDef('WebServer', 'obsolescence_flag'),
|
||||
'finalclass' => MetaModel::GetAttributeDef('WebServer', 'finalclass'),
|
||||
'business_criticity',
|
||||
'description',
|
||||
'name',
|
||||
'friendlyname',
|
||||
'obsolescence_flag',
|
||||
'finalclass',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user