mirror of https://github.com/MISP/MISP
Merge pull request #7615 from JakubOnderka/event_blocklist_unique
Event blocklist uniquepull/7632/head
commit
9523c7c3a9
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -7857,7 +7857,7 @@
|
|||
},
|
||||
"event_blocklists": {
|
||||
"id": true,
|
||||
"event_uuid": false,
|
||||
"event_uuid": true,
|
||||
"event_orgc": false
|
||||
},
|
||||
"event_delegations": {
|
||||
|
|
Loading…
Reference in New Issue