mirror of https://github.com/MISP/MISP
chg: [taxonomy] Faster fetching event and attribute counts for tag
parent
f187780d2a
commit
3d7937cc04
|
@ -85,18 +85,18 @@ class TaxonomiesController extends AppController
|
||||||
}
|
}
|
||||||
$this->loadModel('EventTag');
|
$this->loadModel('EventTag');
|
||||||
$this->loadModel('AttributeTag');
|
$this->loadModel('AttributeTag');
|
||||||
|
|
||||||
|
$tagIds = array_column(array_column(array_column($taxonomy['entries'], 'existing_tag'), 'Tag'), 'id');
|
||||||
|
$eventCount = $this->EventTag->countForTags($tagIds, $this->Auth->user());
|
||||||
|
$attributeTags = $this->AttributeTag->countForTags($tagIds, $this->Auth->user());
|
||||||
|
|
||||||
foreach ($taxonomy['entries'] as $key => $value) {
|
foreach ($taxonomy['entries'] as $key => $value) {
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$count_a = 0;
|
$count_a = 0;
|
||||||
if (!empty($value['existing_tag'])) {
|
if (!empty($value['existing_tag'])) {
|
||||||
foreach ($value['existing_tag'] as $et) {
|
$tagId = $value['existing_tag']['Tag']['id'];
|
||||||
$count = $this->EventTag->find('count', array(
|
$count = isset($eventCount[$tagId]) ? $eventCount[$tagId] : 0;
|
||||||
'conditions' => array('EventTag.tag_id' => $et['id'])
|
$count_a = isset($attributeTags[$tagId]) ? $attributeTags[$tagId] : 0;
|
||||||
));
|
|
||||||
$count_a = $this->AttributeTag->find('count', array(
|
|
||||||
'conditions' => array('AttributeTag.tag_id' => $et['id'])
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$taxonomy['entries'][$key]['events'] = $count;
|
$taxonomy['entries'][$key]['events'] = $count;
|
||||||
$taxonomy['entries'][$key]['attributes'] = $count_a;
|
$taxonomy['entries'][$key]['attributes'] = $count_a;
|
||||||
|
|
|
@ -466,13 +466,12 @@ class Tag extends AppModel
|
||||||
|
|
||||||
public function getTagsByName($tag_names, $containTagConnectors = true)
|
public function getTagsByName($tag_names, $containTagConnectors = true)
|
||||||
{
|
{
|
||||||
$contain = array('EventTag', 'AttributeTag');
|
|
||||||
$tag_params = array(
|
$tag_params = array(
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
'conditions' => array('name' => $tag_names)
|
'conditions' => array('name' => $tag_names)
|
||||||
);
|
);
|
||||||
if ($containTagConnectors) {
|
if ($containTagConnectors) {
|
||||||
$tag_params['contain'] = $contain;
|
$tag_params['contain'] = array('EventTag', 'AttributeTag');
|
||||||
}
|
}
|
||||||
$tags_temp = $this->find('all', $tag_params);
|
$tags_temp = $this->find('all', $tag_params);
|
||||||
$tags = array();
|
$tags = array();
|
||||||
|
|
Loading…
Reference in New Issue