Merge pull request #6131 from JakubOnderka/toggle-correlation-speedup

chg: [internal] Faster generating correlations when enabling
pull/6141/head
Jakub Onderka 2020-07-20 09:21:18 +02:00 committed by GitHub
commit 560894c5f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 12 deletions

View File

@ -5215,10 +5215,6 @@ class EventsController extends AppController
if (!$this->_isSiteAdmin() && !Configure::read('MISP.allow_disabling_correlation')) {
throw new MethodNotAllowedException(__('Disabling the correlation is not permitted on this instance.'));
}
$this->Event->id = $id;
if (!$this->Event->exists()) {
throw new NotFoundException(__('Invalid Event.'));
}
if (!$this->Auth->user('Role')['perm_modify']) {
throw new MethodNotAllowedException(__('You don\'t have permission to do that.'));
}
@ -5240,13 +5236,7 @@ class EventsController extends AppController
if ($event['Event']['disable_correlation']) {
$event['Event']['disable_correlation'] = 0;
$this->Event->save($event);
$attributes = $this->Event->Attribute->find('all', array(
'conditions' => array('Attribute.event_id' => $id),
'recursive' => -1
));
foreach ($attributes as $attribute) {
$this->Event->Attribute->__afterSaveCorrelation($attribute['Attribute'], false, $event);
}
$this->Event->Attribute->generateCorrelation(false, 0, $id);
} else {
$event['Event']['disable_correlation'] = 1;
$this->Event->save($event);

View File

@ -2825,8 +2825,10 @@ class Attribute extends AppModel
// get all attributes..
if (!$eventId) {
$eventIds = $this->Event->find('list', array('recursive' => -1, 'fields' => array('Event.id')));
$full = true;
} else {
$eventIds = array($eventId);
$full = false;
}
$attributeCount = 0;
if (Configure::read('MISP.background_jobs') && $jobId) {
@ -2862,7 +2864,7 @@ class Attribute extends AppModel
}
$attributes = $this->find('all', array('recursive' => -1, 'conditions' => $attributeConditions, 'order' => array()));
foreach ($attributes as $k => $attribute) {
$this->__afterSaveCorrelation($attribute['Attribute'], true, $event);
$this->__afterSaveCorrelation($attribute['Attribute'], $full, $event);
$attributeCount++;
}
}