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