chg: [event:view] Major performance improvement for large event.

Due to the introduction of the event filtering widget, attributes were
fetched 2 additional times.
pull/4492/head
mokaddem 2019-04-16 11:02:52 +02:00
parent a94f1deea6
commit 16453a3433
3 changed files with 40 additions and 16 deletions

View File

@ -1195,12 +1195,9 @@ class EventsController extends AppController
$this->set('advancedFilteringActive', $advancedFiltering['active'] ? 1 : 0);
$this->set('advancedFilteringActiveRules', $advancedFiltering['activeRules']);
$this->set('defaultFilteringRules', $this->defaultFilteringRules);
$attributeTags = $this->Event->Attribute->AttributeTag->getAttributesTags($this->Auth->user(), $event['Event']['id']);
$attributeTags = array_column($attributeTags, 'name');
$this->set('attributeTags', $attributeTags);
$attributeClusters = $this->Event->Attribute->AttributeTag->getAttributesClusters($this->Auth->user(), $event['Event']['id']);
$attributeClusters = array_column($attributeClusters, 'value');
$this->set('attributeClusters', $attributeClusters);
$attributeTagsName = $this->Event->Attribute->AttributeTag->extractAttributeTagsNameFromEvent($event['objects'], 'both');
$this->set('attributeTags', $attributeTagsName['tags']);
$this->set('attributeClusters', $attributeTagsName['clusters']);
$this->disableCache();
$this->layout = 'ajax';
$this->loadModel('Sighting');
@ -1476,12 +1473,9 @@ class EventsController extends AppController
$this->set('advancedFilteringActive', $advancedFiltering['active'] ? 1 : 0);
$this->set('advancedFilteringActiveRules', $advancedFiltering['activeRules']);
$this->set('defaultFilteringRules', $this->defaultFilteringRules);
$attributeTags = $this->Event->Attribute->AttributeTag->getAttributesTags($this->Auth->user(), $event['Event']['id']);
$attributeTags = array_column($attributeTags, 'name');
$this->set('attributeTags', $attributeTags);
$attributeClusters = $this->Event->Attribute->AttributeTag->getAttributesClusters($this->Auth->user(), $event['Event']['id']);
$attributeClusters = array_column($attributeClusters, 'value');
$this->set('attributeClusters', $attributeClusters);
$attributeTagsName = $this->Event->Attribute->AttributeTag->extractAttributeTagsNameFromEvent($event['objects'], 'both');
$this->set('attributeTags', $attributeTagsName['tags']);
$this->set('attributeClusters', $attributeTagsName['clusters']);
$this->set('mitreAttackGalaxyId', $this->Event->GalaxyCluster->Galaxy->getMitreAttackGalaxyId());
$this->set('modificationMapCSV', $modificationMapCSV);
}

View File

@ -234,4 +234,36 @@ class AttributeTag extends AppModel
return $allClusters;
}
public function extractAttributeTagsNameFromEvent(&$event_elements, $to_extract='both')
{
$attribute_tags_name = array('tags' => array(), 'clusters' => array());
if ($to_extract == 'tags' || $to_extract == 'both') {
foreach ($event_elements as $i => $element) {
if ($element['objectType'] == 'object') {
$new_tags = $this->extractAttributeTagsNameFromEvent($element['Attribute'], 'tags');
$attribute_tags_name['tags'] = array_merge($attribute_tags_name['tags'], $new_tags['tags']);
} else {
if (!empty($element['AttributeTag'])) {
$new_tags = Hash::extract($element['AttributeTag'], '{n}.Tag.name');
$attribute_tags_name['tags'] = array_merge($attribute_tags_name['tags'], $new_tags);
}
}
}
}
if ($to_extract == 'clusters' || $to_extract == 'both') {
foreach ($event_elements as $i => $element) {
if ($element['objectType'] == 'object') {
$new_tags = $this->extractAttributeTagsNameFromEvent($element['Attribute'], 'clusters');
$attribute_tags_name['clusters'] = array_merge($attribute_tags_name['clusters'], $new_tags['clusters']);
} else {
if (!empty($element['Galaxy'])) {
$new_tags = Hash::extract($element['Galaxy'], '{n}.GalaxyCluster.{n}.tag_name');
$attribute_tags_name['clusters'] = array_merge($attribute_tags_name['clusters'], $new_tags);
}
}
}
}
return $attribute_tags_name;
}
}

View File

@ -207,7 +207,7 @@ function triggerEventFilteringTool(clicked) {
"unique": true,
"id": "taggedAttributes",
"label": "Tags",
"values": <?php echo json_encode($attributeTags); ?>
"values": <?php echo json_encode(array_map("htmlspecialchars", $attributeTags)); ?>
},
<?php endif; ?>
<?php if (!empty($attributeClusters)): ?>
@ -220,7 +220,7 @@ function triggerEventFilteringTool(clicked) {
"unique": true,
"id": "galaxyAttachedAttributes",
"label": "Galaxies",
"values": <?php echo json_encode($attributeClusters); ?>
"values": <?php echo json_encode(array_map("htmlspecialchars", $attributeClusters)); ?>
},
<?php endif; ?>
{
@ -339,14 +339,12 @@ function triggerEventFilteringTool(clicked) {
{
field: 'taggedAttributes',
id: 'taggedAttributes',
value: '<?php echo isset($filters['taggedAttributes']) ? h($filters['taggedAttributes']) : $attributeTags[0]; ?>'
},
<?php endif; ?>
<?php if (!empty($attributeClusters) && (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['galaxyAttachedAttributes']))): ?>
{
field: 'galaxyAttachedAttributes',
id: 'galaxyAttachedAttributes',
value: '<?php echo isset($filters['galaxyAttachedAttributes']) ? h($filters['galaxyAttachedAttributes']) : $attributeClusters[0]; ?>'
},
<?php endif; ?>
],