mirror of https://github.com/MISP/MISP
fix: [API] massive performance boost for large events with many correlations
- the logic of the JSON converter was heavy and unnecesarypull/5267/head
parent
4b89f430f3
commit
c28314076b
|
@ -43,34 +43,19 @@ class JSONConverterTool
|
|||
//
|
||||
// cleanup the array from things we do not want to expose
|
||||
//
|
||||
$tempSightings = array();
|
||||
if (!empty($event['Sighting'])) {
|
||||
foreach ($event['Sighting'] as $sighting) {
|
||||
$tempSightings[$sighting['attribute_id']][] = $sighting;
|
||||
}
|
||||
unset($event['Sighting']);
|
||||
}
|
||||
unset($event['Event']['user_id']);
|
||||
if (isset($event['Event']['Attribute'])) {
|
||||
$event['Event']['Attribute'] = $this->__cleanAttributes($event['Event']['Attribute']);
|
||||
if (!empty($event['Sighting'])) {
|
||||
foreach ($event['Event']['Attribute'] as $ak => $attribute) {
|
||||
foreach ($event['Sighting'] as $as => $sighting) {
|
||||
if ($attribute['id'] == $sighting['attribute_id']) {
|
||||
$event['Event']['Attribute'][$ak]['Sighting'][] = $sighting;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$event['Event']['Attribute'] = $this->__cleanAttributes($event['Event']['Attribute'], $tempSightings);
|
||||
}
|
||||
if (isset($event['Event']['Object'])) {
|
||||
$event['Event']['Object'] = $this->__cleanObjects($event['Event']['Object']);
|
||||
if (!empty($event['Sighting'])) {
|
||||
foreach ($event['Event']['Object'] as $k => $object) {
|
||||
if (!empty($object['Attribute'])) {
|
||||
foreach ($object['Attribute'] as $ak => $attribute) {
|
||||
foreach ($event['Sighting'] as $as => $sighting) {
|
||||
if ($attribute['id'] == $sighting['attribute_id']) {
|
||||
$event['Event']['Object'][$k]['Attribute'][$ak]['Sighting'][] = $sighting;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$event['Event']['Object'] = $this->__cleanObjects($event['Event']['Object'], $tempSightings);
|
||||
}
|
||||
if (!empty($event['Sighting'])) {
|
||||
unset($event['Sighting']);
|
||||
|
@ -92,18 +77,18 @@ class JSONConverterTool
|
|||
return json_encode($result, JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
private function __cleanAttributes($attributes)
|
||||
private function __cleanAttributes($attributes, $tempSightings = array())
|
||||
{
|
||||
// remove value1 and value2 from the output and remove invalid utf8 characters for the xml parser
|
||||
foreach ($attributes as $key => $value) {
|
||||
if (isset($value['SharingGroup']) && empty($value['SharingGroup'])) {
|
||||
foreach ($attributes as $key => $attribute) {
|
||||
if (isset($attribute['SharingGroup']) && empty($attribute['SharingGroup'])) {
|
||||
unset($attributes[$key]['SharingGroup']);
|
||||
}
|
||||
unset($attributes[$key]['value1']);
|
||||
unset($attributes[$key]['value2']);
|
||||
unset($attributes[$key]['category_order']);
|
||||
if (isset($event['RelatedAttribute'][$value['id']])) {
|
||||
$attributes[$key]['RelatedAttribute'] = $event['Event']['RelatedAttribute'][$value['id']];
|
||||
if (isset($event['RelatedAttribute'][$attribute['id']])) {
|
||||
$attributes[$key]['RelatedAttribute'] = $event['Event']['RelatedAttribute'][$attribute['id']];
|
||||
foreach ($attributes[$key]['RelatedAttribute'] as &$ra) {
|
||||
$ra = array('Attribute' => $ra);
|
||||
}
|
||||
|
@ -115,15 +100,18 @@ class JSONConverterTool
|
|||
}
|
||||
unset($attributes[$key]['AttributeTag']);
|
||||
}
|
||||
if (!empty($tempSightings[$attribute['id']])) {
|
||||
$attributes[$key]['Sighting'] = $tempSightings[$attribute['id']];
|
||||
}
|
||||
}
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
private function __cleanObjects($objects)
|
||||
private function __cleanObjects($objects, $tempSightings = array())
|
||||
{
|
||||
foreach ($objects as $k => $object) {
|
||||
if (!empty($object['Attribute'])) {
|
||||
$objects[$k]['Attribute'] = $this->__cleanAttributes($object['Attribute']);
|
||||
$objects[$k]['Attribute'] = $this->__cleanAttributes($object['Attribute'], $tempSightings);
|
||||
} else {
|
||||
unset($objects[$k]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue