R
R
ragnar_ok2019-10-04 15:21:07
1C-Bitrix
ragnar_ok, 2019-10-04 15:21:07

How to reduce the number of requests to get the "Directory" property?

I get the "Directory" property. The number of requests is equal to the number of loop iterations:

foreach ($arResult['ITEMS'] as $index => $arItem) {
    $resultArray = \Bitrix\Highloadblock\HighloadBlockTable::compileEntity('Entity')->getDataClass()::getList([
        'select' => ['UF_NAME'],
        'filter' => ['UF_XML_ID' => $arItem['PROPERTIES']['PROP']['VALUE']],
    ]);
    while ($rowArray = $resultObj->fetch()) {
        $arResult['ITEMS'][$index]['PROPERTIES']['PROP']['UF_NAME'] = $resultArray['UF_NAME'];
    }
}

How to use the example of this code to reduce the number of queries and get all the values ​​in:
$arResult['ITEMS'][$index]['PROPERTIES']['PROP']['UF_NAME']

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Georgy Baruchyan, 2019-10-04
@ragnar_ok

First you need to collect an array of all xml_id for which you will search

$xmlIds = [];

foreach ($arResult['ITEMS'] as $index => $arItem) {
    $xmlIds[] = $arItem['PROPERTIES']['PROP']['VALUE']];
}

Let's remove duplicates just in case:
Find find all records from HL with UF_XML_ID
if(!empty($xmlIds)){
  $resultArray = \Bitrix\Highloadblock\HighloadBlockTable::compileEntity('Entity')->getDataClass()::getList([
        'select' => ['UF_NAME'],
        'filter' => ['@UF_XML_ID' => $xmlIds],
    ]);
    
  while ($rowArray = $resultObj->fetch()) {
      $arRef[$resultArray['UF_XML_ID']] = $resultArray['UF_NAME'];
  }	
}

A
Alexander, 2019-10-04
Madzhugin @Suntechnic

If straight stupidly in the forehead:

$arRef = [];
$resultArray = \Bitrix\Highloadblock\HighloadBlockTable::compileEntity('Entity')->getDataClass()::getList([
        'select' => ['UF_NAME'],
        'filter' => [],
    ]);
while ($rowArray = $resultObj->fetch()) {
    $arRef[$resultArray['UF_XML_ID']] = $resultArray['UF_NAME'];
}
foreach ($arResult['ITEMS'] as $index => $arItem) {
    $arResult['ITEMS'][$index]['PROPERTIES']['PROP']['UF_NAME'] = $arRef[$arItem['PROPERTIES']['PROP']['VALUE']];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question