chg: [internal] Speedup sightings saving

pull/6542/head
Jakub Onderka 2020-11-02 17:42:48 +01:00
parent 557c4f59e3
commit a92c1c4fe4
2 changed files with 16 additions and 6 deletions

View File

@ -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

View File

@ -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.';
}