mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 01:28:47 +02:00
N°7636 - Too many OQL requests executed in order to display a lnk (#661)
This commit is contained in:
@@ -698,10 +698,10 @@ HTML
|
||||
$sLinkedClass = $oAttDef->GetLinkedClass();
|
||||
|
||||
// Filter out links pointing to obsolete objects (if relevant)
|
||||
$oOrmLinkSet = $this->Get($sAttCode);
|
||||
$oLinkSet = $oOrmLinkSet->ToDBObjectSet(utils::ShowObsoleteData());
|
||||
$oOrmLinkSet = $this->Get($sAttCode);
|
||||
$oLinkSet = $oOrmLinkSet->ToDBObjectSet(utils::ShowObsoleteData());
|
||||
$iCount = $oLinkSet->Count();
|
||||
|
||||
$iCount = $oLinkSet->Count();
|
||||
if ($this->IsNew()) {
|
||||
$iFlags = $this->GetInitialStateAttributeFlags($sAttCode);
|
||||
} else {
|
||||
@@ -766,9 +766,9 @@ HTML
|
||||
$oPage->add($sHTMLValue);
|
||||
} else {
|
||||
if ($oAttDef->IsIndirect()) {
|
||||
$oBlockLinkSetViewTable = new BlockIndirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef, $bReadOnly);
|
||||
$oBlockLinkSetViewTable = new BlockIndirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef, $bReadOnly, $iCount);
|
||||
} else {
|
||||
$oBlockLinkSetViewTable = new BlockDirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef, $bReadOnly);
|
||||
$oBlockLinkSetViewTable = new BlockDirectLinkSetViewTable($oPage, $this, $sClass, $sAttCode, $oAttDef, $bReadOnly, $iCount);
|
||||
}
|
||||
$oPage->AddUiBlock($oBlockLinkSetViewTable);
|
||||
}
|
||||
@@ -5190,7 +5190,7 @@ HTML
|
||||
$aKeys = array_keys($aValues[$sAttCode]);
|
||||
$currValue = $aKeys[0]; // The only value is the first key
|
||||
if ($oAttDef->GetEditClass() == 'LinkedSet') {
|
||||
$oOrmLinkSet = $oDummyObj->Get($sAttCode);
|
||||
$oOrmLinkSet = $oDummyObj->Get($sAttCode);
|
||||
LinkSetDataTransformer::StringToOrmLinkSet($aValues[$sAttCode][$currValue]['edit_value'], $oOrmLinkSet);
|
||||
|
||||
} else {
|
||||
@@ -5244,7 +5244,7 @@ HTML
|
||||
}
|
||||
$oDummyObj->Set($sAttCode, $oTagSet);
|
||||
} else if ($oAttDef->GetEditClass() == 'LinkedSet') {
|
||||
$oOrmLinkSet = $oDummyObj->Get($sAttCode);
|
||||
$oOrmLinkSet = $oDummyObj->Get($sAttCode);
|
||||
foreach ($aMultiValues as $key => $sValue) {
|
||||
LinkSetDataTransformer::StringToOrmLinkSet($sValue['edit_value'], $oOrmLinkSet);
|
||||
}
|
||||
|
||||
@@ -263,6 +263,8 @@ class DisplayBlock
|
||||
/** param for export.php */
|
||||
'refresh_action',
|
||||
/**to add refresh button in datatable*/
|
||||
'object_count',
|
||||
/** int number of objects in list */
|
||||
], DataTableUIBlockFactory::GetAllowedParams()),
|
||||
static::ENUM_STYLE_LIST_SEARCH => array_merge([
|
||||
'update_history',
|
||||
@@ -1860,7 +1862,11 @@ class MenuBlock extends DisplayBlock
|
||||
$aSelectedClasses = $this->GetFilter()->GetSelectedClasses();
|
||||
$bIsForLinkset = isset($aExtraParams['target_attr']);
|
||||
$oSet = new CMDBObjectSet($this->GetFilter());
|
||||
$iSetCount = $oSet->Count();
|
||||
if(isset($aExtraParams['object_count'])){
|
||||
$iSetCount = $aExtraParams['object_count'];
|
||||
} else {
|
||||
$iSetCount = $oSet->Count();
|
||||
}
|
||||
/** @var string $sRefreshAction JS snippet to run when clicking on the refresh button of the menu */
|
||||
$sRefreshAction = $aExtraParams['refresh_action'] ?? '';
|
||||
$bIsCreationInModal = isset($aExtraParams['creation_in_modal']) && $aExtraParams['creation_in_modal'] === true;
|
||||
|
||||
@@ -7112,7 +7112,7 @@ abstract class MetaModel
|
||||
if ($iKey < 0) {
|
||||
return "$sTargetClass: $iKey (invalid value)";
|
||||
}
|
||||
$oObj = self::GetObject($sTargetClass, $iKey, false);
|
||||
$oObj = self::GetObject($sTargetClass, $iKey, false);
|
||||
if (is_null($oObj)) {
|
||||
// Whatever we are looking for, the root class is the key to search for
|
||||
$sRootClass = self::GetRootClass($sTargetClass);
|
||||
|
||||
@@ -82,6 +82,7 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock
|
||||
protected bool $bIsAllowCreate;
|
||||
protected bool $bIsAllowModify;
|
||||
protected bool $bIsAllowDelete;
|
||||
protected int $iCount;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -95,7 +96,7 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock
|
||||
*
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function __construct(WebPage $oPage, DBObject $oDbObject, string $sObjectClass, string $sAttCode, AttributeLinkedSet $oAttDef, bool $bIsReadOnly = false)
|
||||
public function __construct(WebPage $oPage, DBObject $oDbObject, string $sObjectClass, string $sAttCode, AttributeLinkedSet $oAttDef, bool $bIsReadOnly = false, ?int $iCount = null)
|
||||
{
|
||||
parent::__construct("links_view_table_$sAttCode", ["ibo-block-links-table"]);
|
||||
|
||||
@@ -106,6 +107,7 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock
|
||||
$this->oDbObject = $oDbObject;
|
||||
$this->sTableId = 'rel_'.$this->sAttCode;
|
||||
$this->bIsAttEditable = !$bIsReadOnly;
|
||||
$this->iCount = $iCount;
|
||||
$this->SetDataAttributes(['role' => 'ibo-block-links-table', 'link-attcode' => $sAttCode, 'link-class' => $this->oAttDef->GetLinkedClass()]);
|
||||
// Initialization
|
||||
$this->Init();
|
||||
@@ -195,9 +197,13 @@ abstract class AbstractBlockLinkSetViewTable extends UIContentBlock
|
||||
$oOrmLinkSet = $this->oDbObject->Get($this->sAttCode);
|
||||
$oLinkSet = $oOrmLinkSet->ToDBObjectSet(utils::ShowObsoleteData());
|
||||
|
||||
$aExtraParams = $this->GetExtraParam();
|
||||
if (is_null($this->iCount) === false) {
|
||||
$aExtraParams['object_count' ] = $this->iCount;
|
||||
}
|
||||
// add list block
|
||||
$oBlock = new DisplayBlock($oLinkSet->GetFilter(), DisplayBlock::ENUM_STYLE_LIST_IN_OBJECT, false);
|
||||
$this->AddSubBlock($oBlock->GetRenderContent($oPage, $this->GetExtraParam(), $this->sTableId));
|
||||
$this->AddSubBlock($oBlock->GetRenderContent($oPage, $aExtraParams, $this->sTableId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -70,8 +70,14 @@ class AjaxRenderController
|
||||
$bShowObsoleteData = utils::ShowObsoleteData();
|
||||
}
|
||||
$oSet->SetShowObsoleteData($bShowObsoleteData);
|
||||
$iCount = 0;
|
||||
if (isset($aExtraParams['object_count'])) {
|
||||
$iCount = $aExtraParams['object_count'];
|
||||
} else {
|
||||
$iCount = $oSet->Count();
|
||||
}
|
||||
$aResult["draw"] = $iDrawNumber;
|
||||
$aResult["recordsTotal"] = $oSet->Count();
|
||||
$aResult["recordsTotal"] = $iCount;
|
||||
$aResult["recordsFiltered"] = $aResult["recordsTotal"] ;
|
||||
$aResult["data"] = [];
|
||||
while ($aObject = $oSet->FetchAssoc()) {
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Attachment;
|
||||
use AttributeDateTime;
|
||||
use Combodo\iTop\Application\WebPage\iTopWebPage;
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
use Combodo\iTop\Service\Events\EventData;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use CoreException;
|
||||
@@ -1415,4 +1417,28 @@ class DBObjectTest extends ItopDataTestCase
|
||||
$this->assertEquals("2024-01-15 09:45:00", $oObject->Get('end_date'), 'SetComputedDate +2 weeks on a WorkOrder DateTimeAttribute');
|
||||
|
||||
}
|
||||
/**
|
||||
* @covers DBObject::Get
|
||||
*/
|
||||
public function testGetLinkSet()
|
||||
{
|
||||
$iServer = $this->GivenObjectInDB('Server', [
|
||||
'name' => 'The Boss',
|
||||
]);
|
||||
|
||||
$iUserRequest = $this->GivenObjectInDB('UserRequest', [
|
||||
'ref' => 'UR1', 'title' => 'UR1', 'description' => 'UR1', 'caller_id' => 3, 'org_id' => 3, 'service_id' => 1,
|
||||
'functionalcis_list' => [
|
||||
"functionalci_id:$iServer"
|
||||
],
|
||||
]);
|
||||
$oUserRequest = MetaModel::GetObject('UserRequest', $iUserRequest);
|
||||
|
||||
$this->assertDBQueryCount(2, function () use (&$oUserRequest) {
|
||||
$oUserRequest->Get('functionalcis_list');
|
||||
});
|
||||
$this->assertDBQueryCount(0, function () use (&$oUserRequest) {
|
||||
$oUserRequest->Get('functionalcis_list');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user