mirror of https://github.com/MISP/MISP
fix: Further performance tweaks to the feed fetcher
parent
6b6ea52b58
commit
6c7c40e773
|
@ -279,25 +279,25 @@ class FeedsController extends AppController {
|
|||
true
|
||||
);
|
||||
$this->Job->saveField('process_id', $process_id);
|
||||
$message = array('result' => 'Pull queued for background execution.');
|
||||
$message = 'Pull queued for background execution.';
|
||||
} else {
|
||||
$result = $this->Feed->downloadFromFeedInitiator($feedId, $this->Auth->user());
|
||||
if (!$result) {
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData('Fetching the feed has failed.', $this->response->type());
|
||||
return $this->RestResponse->viewData(array('result' => 'Fetching the feed has failed.'), $this->response->type());
|
||||
} else {
|
||||
$this->Session->setFlash('Fetching the feed has failed.');
|
||||
$this->redirect(array('action' => 'index'));
|
||||
}
|
||||
}
|
||||
$message = array('result' => 'Fetching the feed has successfuly completed.');
|
||||
$message = 'Fetching the feed has successfuly completed.';
|
||||
if ($this->Feed->data['Feed']['source_format'] == 'misp') {
|
||||
if (isset($result['add'])) $message['result'] .= ' Downloaded ' . count($result['add']) . ' new event(s).';
|
||||
if (isset($result['edit'])) $message['result'] .= ' Updated ' . count($result['edit']) . ' event(s).';
|
||||
}
|
||||
}
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData($message, $this->response->type());
|
||||
return $this->RestResponse->viewData(array('result' => $message), $this->response->type());
|
||||
} else {
|
||||
$this->Session->setFlash($message);
|
||||
$this->redirect(array('action' => 'index'));
|
||||
|
|
|
@ -37,6 +37,13 @@ class UsersController extends AppController {
|
|||
if (!$this->_isSiteAdmin() && $this->Auth->user('id') != $id) {
|
||||
throw new NotFoundException(__('Invalid user or not authorised.'));
|
||||
}
|
||||
if (!is_numeric($id) && !empty($id)) {
|
||||
$userId = $this->User->find('first', array(
|
||||
'conditions' => array('email' => $id),
|
||||
'fields' => array('id')
|
||||
));
|
||||
$id = $userid['User']['id'];
|
||||
}
|
||||
$this->User->id = $id;
|
||||
$this->User->recursive = 0;
|
||||
if (!$this->User->exists()) {
|
||||
|
|
|
@ -704,33 +704,39 @@ class Feed extends AppModel {
|
|||
}
|
||||
}
|
||||
if ($feed['Feed']['fixed_event']) {
|
||||
$event = $this->Event->find('first', array(
|
||||
$temp = $this->Event->Attribute->find('all', array(
|
||||
'conditions' => array(
|
||||
'Event.id' => $event['Event']['id']),
|
||||
'recursive' => -1,
|
||||
'contain' => array(
|
||||
'Attribute' => array(
|
||||
'conditions' => array(
|
||||
'Attribute.deleted' => 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
'Attribute.deleted' => 0,
|
||||
'Attribute.event_id' => $event['Event']['id']
|
||||
),
|
||||
'recursive' => -1,
|
||||
'fields' => array('id', 'value1', 'value2')
|
||||
));
|
||||
$event['Attribute'] = array();
|
||||
foreach ($temp as $k => $t) {
|
||||
$start = microtime(true);
|
||||
if (!empty($t['Attribute']['value2'])) {
|
||||
$t['Attribute']['value'] = $t['Attribute']['value1'] . '|' . $t['Attribute']['value2'];
|
||||
} else {
|
||||
$t['Attribute']['value'] = $t['Attribute']['value1'];
|
||||
}
|
||||
$event['Attribute'][$t['Attribute']['id']] = $t['Attribute']['value'];
|
||||
}
|
||||
unset($temp);
|
||||
$to_delete = array();
|
||||
foreach ($data as $k => $dataPoint) {
|
||||
foreach ($event['Attribute'] as $attribute_key => $attribute) {
|
||||
if ($dataPoint['value'] == $attribute['value'] && $dataPoint['type'] == $attribute['type'] && $attribute['category'] == $dataPoint['category']) {
|
||||
unset($data[$k]);
|
||||
unset($event['Attribute'][$attribute_key]);
|
||||
}
|
||||
$finder = array_search($dataPoint['value'], $event['Attribute']);
|
||||
if ($finder !== false) {
|
||||
unset($data[$k]);
|
||||
unset($event['Attribute'][$finder]);
|
||||
}
|
||||
}
|
||||
if ($feed['Feed']['delta_merge']) {
|
||||
foreach ($event['Attribute'] as $attribute) {
|
||||
$to_delete[] = $attribute['id'];
|
||||
foreach ($event['Attribute'] as $k => $attribute) {
|
||||
$to_delete[] = $k;
|
||||
}
|
||||
if (!empty($to_delete)) {
|
||||
$this->Event->Attribute->deleteAll(array('Attribute.id' => $to_delete));
|
||||
$this->Event->Attribute->deleteAll(array('Attribute.id' => $to_delete, 'Attribute.deleted' => 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue