new: [settings] added setting to (temporarily) disable the loading of sightings via the API

- affected endpoints: restsearch and /events/view
- temporarily skips the loading of sightings

- helps alleviate absolutely massive sighting data sets from killing server performance
- temporary measure, doesn't prevent the creation of sightings / viewing of sightings via the UI
pull/9615/head
iglocska 2024-03-12 08:24:13 +01:00
parent 661b238b3f
commit 3c79ebbc06
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
3 changed files with 41 additions and 26 deletions

View File

@ -1406,14 +1406,13 @@ class Event extends AppModel
return $this->delete(null, false);
}
public function createEventConditions($user)
public function createEventConditions($user, $skip_own_event_rule = false)
{
$conditions = array();
if (!$user['Role']['perm_site_admin']) {
$sgids = $this->SharingGroup->authorizedIds($user);
$unpublishedPrivate = Configure::read('MISP.unpublishedprivate');
$conditions['AND']['OR'] = [
'Event.org_id' => $user['org_id'],
[
'AND' => [
'Event.distribution >' => 0,
@ -1429,6 +1428,9 @@ class Event extends AppModel
]
]
];
if (!$skip_own_event_rule) {
$conditions['AND']['OR'][] = ['Event.org_id' => $user['org_id']];
}
}
return $conditions;
}
@ -2279,7 +2281,9 @@ class Event extends AppModel
$event['EventReport'] = $this->__attachSharingGroups($event['EventReport'], $sharingGroupData);
}
if (empty($options['metadata']) && empty($options['noSightings'])) {
$event['Sighting'] = $this->Sighting->attachToEvent($event, $user);
if (empty(Configure::read('MISP.disable_sighting_loading'))) {
$event['Sighting'] = $this->Sighting->attachToEvent($event, $user);
}
}
if ($options['includeSightingdb']) {
$this->Sightingdb = ClassRegistry::init('Sightingdb');

View File

@ -5123,6 +5123,14 @@ class Server extends AppModel
'type' => 'numeric',
'null' => true
),
'disable_sighting_loading' => [
'level' => 1,
'description' => __('If an instance has an extremely high number of sightings, including the sightings in the search algorithms can bring an instance to a grinding halt. Enable this setting to temporarily disable the search until the issue is remedied. This setting will also disable sightings from being attached via /events/view API calls.'),
'value' => false,
'test' => 'testBoolFalse',
'type' => 'boolean',
'null' => true
],
'disable_event_locks' => [
'level' => 1,
'description' => __('Disable the event locks that are executed periodically when a user browses an event view. It can be useful to leave event locks enabled to warn users that someone else is editing the same event, but generally it\'s extremely verbose and can cause issues in certain setups, so it\'s recommended to disable this.'),

View File

@ -1136,34 +1136,37 @@ class Sighting extends AppModel
$tmpfile->write($exportTool->header($exportToolParams));
$separator = $exportTool->separator($exportToolParams);
// fetch sightings matching the query without ACL checks
if (!empty($conditions['Sighting.event_id']) && is_array($conditions['Sighting.event_id'])) {
$conditions_copy = $conditions;
$sightingIds = [];
foreach ($conditions['Sighting.event_id'] as $e_id) {
$conditions_copy['Sighting.event_id'] = $e_id;
$tempIds = $this->find('column', [
if (empty(Configure::read('MISP.disable_sighting_loading'))) {
// fetch sightings matching the query without ACL checks
if (!empty($conditions['Sighting.event_id']) && is_array($conditions['Sighting.event_id'])) {
$conditions_copy = $conditions;
$sightingIds = [];
foreach ($conditions['Sighting.event_id'] as $e_id) {
$conditions_copy['Sighting.event_id'] = $e_id;
$tempIds = $this->find('column', [
'conditions' => $conditions,
'fields' => ['Sighting.id'],
'contain' => $contain
]);
if (!empty($tempIds)) {
$sightingIds = array_merge($sightingIds, $tempIds);
}
}
} else {
$sightingIds = $this->find('column', [
'conditions' => $conditions,
'fields' => ['Sighting.id'],
'contain' => $contain
]);
if (!empty($tempIds)) {
$sightingIds = array_merge($sightingIds, $tempIds);
}
}
} else {
$sightingIds = $this->find('column', [
'conditions' => $conditions,
'fields' => ['Sighting.id'],
'contain' => $contain
]);
}
foreach (array_chunk($sightingIds, 500) as $chunk) {
// fetch sightings with ACL checks and sighting policies
$sightings = $this->getSightings($user, $chunk, $includeEvent, $includeAttribute, $includeUuid);
foreach ($sightings as $sighting) {
$tmpfile->writeWithSeparator($exportTool->handler($sighting, $exportToolParams), $separator);
foreach (array_chunk($sightingIds, 500) as $chunk) {
// fetch sightings with ACL checks and sighting policies
$sightings = $this->getSightings($user, $chunk, $includeEvent, $includeAttribute, $includeUuid);
foreach ($sightings as $sighting) {
$tmpfile->writeWithSeparator($exportTool->handler($sighting, $exportToolParams), $separator);
}
}
}