Merge pull request #7615 from JakubOnderka/event_blocklist_unique

Event blocklist unique
pull/7632/head
Jakub Onderka 2021-08-05 12:49:41 +02:00 committed by GitHub
commit 9523c7c3a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 12 deletions

View File

@ -299,7 +299,7 @@ CREATE TABLE IF NOT EXISTS `event_blocklists` (
`comment` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`event_orgc` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`),
INDEX `event_uuid` (`event_uuid`),
UNIQUE INDEX `event_uuid` (`event_uuid`),
INDEX `event_orgc` (`event_orgc`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

View File

@ -49,6 +49,28 @@ class EventBlocklist extends AppModel
return true;
}
/**
* @param array $eventArray
*/
public function removeBlockedEvents(array &$eventArray)
{
// When event array contains a lot events, it is more efficient to fetch all blocked events
$conditions = count($eventArray) > 10000 ? [] : ['EventBlocklist.event_uuid' => array_column($eventArray, 'uuid')];
$blocklistHits = $this->find('column', [
'conditions' => $conditions,
'fields' => ['EventBlocklist.event_uuid'],
]);
if (empty($blocklistHits)) {
return;
}
$blocklistHits = array_flip($blocklistHits);
foreach ($eventArray as $k => $event) {
if (isset($blocklistHits[$event['uuid']])) {
unset($eventArray[$k]);
}
}
}
/**
* @param string $eventUuid
* @return bool

View File

@ -838,16 +838,7 @@ class Server extends AppModel
} else {
if (Configure::read('MISP.enableEventBlocklisting') !== false) {
$this->EventBlocklist = ClassRegistry::init('EventBlocklist');
$blocklistHits = $this->EventBlocklist->find('column', array(
'conditions' => array('EventBlocklist.event_uuid' => array_column($eventArray, 'uuid')),
'fields' => array('EventBlocklist.event_uuid'),
));
$blocklistHits = array_flip($blocklistHits);
foreach ($eventArray as $k => $event) {
if (isset($blocklistHits[$event['uuid']])) {
unset($eventArray[$k]);
}
}
$this->EventBlocklist->removeBlockedEvents($eventArray);
}
if (Configure::read('MISP.enableOrgBlocklisting') !== false) {

View File

@ -7857,7 +7857,7 @@
},
"event_blocklists": {
"id": true,
"event_uuid": false,
"event_uuid": true,
"event_orgc": false
},
"event_delegations": {