chg: [internal] Little optimise Event::getRelatedAttributes

pull/6288/head
Jakub Onderka 2020-09-04 22:19:02 +02:00
parent e475b2bf7f
commit 7b47d49836
1 changed files with 2 additions and 11 deletions

View File

@ -870,19 +870,13 @@ class Event extends AppModel
return $relatedEvents;
}
public function getRelatedAttributes($user, $id = null, $sgids, $shadowAttribute = false, $scope = 'event')
public function getRelatedAttributes($user, $id, $sgids, $shadowAttribute = false, $scope = 'event')
{
if ($shadowAttribute) {
$settings = array('model' => 'ShadowAttribute', 'correlationModel' => 'ShadowAttributeCorrelation', 'parentIdField' => '1_shadow_attribute_id');
} else {
$settings = array('model' => 'Attribute', 'correlationModel' => 'Correlation', 'parentIdField' => '1_attribute_id');
}
if ($scope === 'event' && $id == null) {
$id = $this->data['Event']['id'];
} elseif ($scope === 'attribute' && $id == null) {
$id = $this->data['Attribute']['id'];
}
if (!isset($sgids) || empty($sgids)) {
$sgids = array(-1);
}
@ -937,10 +931,7 @@ class Event extends AppModel
} else {
$conditionsCorrelation = array($settings['correlationModel'] . '.1_' . $scope . '_id' => $id);
}
$max_correlations = Configure::read('MISP.max_correlations_per_event');
if (empty($max_correlations)) {
$max_correlations = 5000;
}
$max_correlations = Configure::read('MISP.max_correlations_per_event') ?: 5000;
$correlations = $this->{$settings['correlationModel']}->find('all', array(
'fields' => ['event_id', 'attribute_id', 'value', $settings['parentIdField']],
'conditions' => $conditionsCorrelation,