fix: [correlations] Prevent Trying to access array offset on value of type null error

pull/8603/head
Jakub Onderka 2022-09-21 16:12:45 +02:00
parent 928de2de4b
commit 196c87963d
1 changed files with 16 additions and 9 deletions

View File

@ -681,6 +681,11 @@ class Correlation extends AppModel
return true;
}
/**
* @param array $query
* @return array|false
* @throws RedisException
*/
public function findTop(array $query)
{
try {
@ -688,21 +693,23 @@ class Correlation extends AppModel
} catch (Exception $e) {
return false;
}
$start = $query['limit'] * ($query['page'] -1);
$end = $query['limit'] * $query['page'] - 1;
$list = $redis->zRevRange(self::CACHE_NAME, $start, $end, true);
$results = [];
foreach ($list as $value => $count) {
$realValue = $this->CorrelationValue->find('first',
[
'recursive' => -1,
'conditions' => ['CorrelationValue.id' => $value],
'fields' => 'CorrelationValue.value'
]
);
$realValues = $this->CorrelationValue->find('list', [
'recursive' => -1,
'conditions' => ['CorrelationValue.id' => array_keys($list)],
'fields' => ['CorrelationValue.id', 'CorrelationValue.value'],
]);
foreach ($list as $valueId => $count) {
$value = $realValues[$valueId] ?? null;
$results[] = [
'Correlation' => [
'value' => $realValue['CorrelationValue']['value'],
'value' => $value,
'count' => $count,
'excluded' => $this->__preventExcludedCorrelations($value),
]