mirror of https://github.com/MISP/MISP
chg: [internal] Speedup sightings saving
parent
557c4f59e3
commit
a92c1c4fe4
|
@ -3249,13 +3249,20 @@ class Attribute extends AppModel
|
|||
return $attribute;
|
||||
}
|
||||
|
||||
public function fetchAttributesSimple($user, $options = array())
|
||||
/**
|
||||
* Fetches attributes that $user can see.
|
||||
*
|
||||
* @param array $user
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
public function fetchAttributesSimple(array $user, array $options = array())
|
||||
{
|
||||
$params = array(
|
||||
'conditions' => $this->buildConditions($user),
|
||||
'fields' => array(),
|
||||
'recursive' => -1,
|
||||
'contain' => array()
|
||||
'contain' => ['Event', 'Object'], // by default include Event and Object, because it is required for conditions
|
||||
);
|
||||
if (isset($options['conditions'])) {
|
||||
$params['conditions']['AND'][] = $options['conditions'];
|
||||
|
@ -3266,14 +3273,13 @@ class Attribute extends AppModel
|
|||
if (isset($options['contain'])) {
|
||||
$params['contain'] = $options['contain'];
|
||||
}
|
||||
$results = $this->find('all', array(
|
||||
return $this->find('all', array(
|
||||
'conditions' => $params['conditions'],
|
||||
'recursive' => -1,
|
||||
'fields' => $params['fields'],
|
||||
'contain' => $params['contain'],
|
||||
'sort' => false
|
||||
));
|
||||
return $results;
|
||||
}
|
||||
|
||||
// Method that fetches all attributes for the various exports
|
||||
|
|
|
@ -321,7 +321,8 @@ class Sighting extends AppModel
|
|||
// if sighting with given uuid already exists and quit early
|
||||
$existing_sighting = $this->find('count', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('uuid' => $sighting_uuid)
|
||||
'conditions' => array('uuid' => $sighting_uuid),
|
||||
'callbacks' => false,
|
||||
));
|
||||
if ($existing_sighting) {
|
||||
return 0;
|
||||
|
@ -351,7 +352,10 @@ class Sighting extends AppModel
|
|||
}
|
||||
}
|
||||
}
|
||||
$attributes = $this->Attribute->fetchAttributes($user, array('conditions' => $conditions, 'flatten' => 1));
|
||||
$attributes = $this->Attribute->fetchAttributesSimple($user, [
|
||||
'conditions' => $conditions,
|
||||
'fields' => ['Attribute.id', 'Attribute.event_id'],
|
||||
]);
|
||||
if (empty($attributes)) {
|
||||
return 'No valid attributes found that match the criteria.';
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue