mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
(Retrofit from trunk) N°1330 Header with statistics dashlet perf improvements
Now uses one count + group by query instead of one count query per grouping value (r5576) SVN:2.4[5577]
This commit is contained in:
@@ -774,21 +774,37 @@ class DisplayBlock
|
|||||||
{
|
{
|
||||||
$aStates = explode(',', $sStatesList);
|
$aStates = explode(',', $sStatesList);
|
||||||
$oAttDef = MetaModel::GetAttributeDef($sClass, $sStateAttrCode);
|
$oAttDef = MetaModel::GetAttributeDef($sClass, $sStateAttrCode);
|
||||||
|
|
||||||
|
// Generate one count + group by query [#1330]
|
||||||
|
$oGroupByExpr = Expression::FromOQL($sClass.'.'.$sStateAttrCode);
|
||||||
|
$aGroupBy = array('group1' => $oGroupByExpr);
|
||||||
|
$sCountGroupByQuery = $this->m_oFilter->MakeGroupByQuery(array(), $aGroupBy, false);
|
||||||
|
$aCountGroupByResults = CMDBSource::QueryToArray($sCountGroupByQuery);
|
||||||
|
$aCountsQueryResults = array();
|
||||||
|
foreach ($aCountGroupByResults as $aCountGroupBySingleResult)
|
||||||
|
{
|
||||||
|
$aCountsQueryResults[$aCountGroupBySingleResult[0]] = $aCountGroupBySingleResult[1];
|
||||||
|
}
|
||||||
|
|
||||||
foreach($aStates as $sStateValue)
|
foreach($aStates as $sStateValue)
|
||||||
{
|
{
|
||||||
$oFilter = $this->m_oFilter->DeepClone();
|
|
||||||
$oFilter->AddCondition($sStateAttrCode, $sStateValue, '=');
|
|
||||||
$oSet = new DBObjectSet($oFilter);
|
|
||||||
$oSet->SetShowObsoleteData($this->m_bShowObsoleteData);
|
|
||||||
$aCounts[$sStateValue] = $oSet->Count();
|
|
||||||
$aStateLabels[$sStateValue] = htmlentities($oAttDef->GetValueLabel($sStateValue), ENT_QUOTES, 'UTF-8');
|
$aStateLabels[$sStateValue] = htmlentities($oAttDef->GetValueLabel($sStateValue), ENT_QUOTES, 'UTF-8');
|
||||||
|
|
||||||
|
$aCounts[$sStateValue] = (array_key_exists($sStateValue, $aCountsQueryResults))
|
||||||
|
? $aCountsQueryResults[$sStateValue]
|
||||||
|
: 0;
|
||||||
|
|
||||||
if ($aCounts[$sStateValue] == 0)
|
if ($aCounts[$sStateValue] == 0)
|
||||||
{
|
{
|
||||||
$aCounts[$sStateValue] = '-';
|
$aCounts[$sStateValue] = '-';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search&'.$oAppContext->GetForLink().'&filter='.urlencode($oFilter->serialize());
|
$oSingleGroupByValueFilter = $this->m_oFilter->DeepClone();
|
||||||
|
$oSingleGroupByValueFilter->AddCondition($sStateAttrCode, $sStateValue, '=');
|
||||||
|
$sHyperlink = utils::GetAbsoluteUrlAppRoot()
|
||||||
|
.'pages/UI.php?operation=search&'.$oAppContext->GetForLink()
|
||||||
|
.'&filter='.urlencode($oSingleGroupByValueFilter->serialize());
|
||||||
$aCounts[$sStateValue] = "<a href=\"$sHyperlink\">{$aCounts[$sStateValue]}</a>";
|
$aCounts[$sStateValue] = "<a href=\"$sHyperlink\">{$aCounts[$sStateValue]}</a>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user