mirror of https://github.com/MISP/MISP
chg: cache Taxonomy:getTaxonomyForTag()
parent
53b0e4918b
commit
c82f8e5d03
|
@ -293,6 +293,11 @@ Cache::config('_cake_model_', array(
|
|||
'duration' => $duration
|
||||
));
|
||||
|
||||
Cache::config('misp_short', array(
|
||||
'engine' => $engine,
|
||||
'duration' => '1800', // 30 minutes
|
||||
'prefix' => 'misp_cache_short_',
|
||||
));
|
||||
|
||||
//Comment the following out if you do not with to use the background workers (not recommended)
|
||||
require_once dirname(__DIR__) . '/Vendor/autoload.php';
|
||||
|
|
|
@ -33,6 +33,8 @@ class Taxonomy extends AppModel
|
|||
)
|
||||
);
|
||||
|
||||
private $localLookupTable = [];
|
||||
|
||||
public function update()
|
||||
{
|
||||
$existing = $this->find('all', array(
|
||||
|
@ -588,46 +590,53 @@ class Taxonomy extends AppModel
|
|||
return false; // not taxonomy tag
|
||||
}
|
||||
|
||||
if (isset($splits['value'])) {
|
||||
$contain = array(
|
||||
'TaxonomyPredicate' => array(
|
||||
'TaxonomyEntry' => array()
|
||||
)
|
||||
);
|
||||
if (!$fullTaxonomy) {
|
||||
$contain['TaxonomyPredicate']['conditions'] = array(
|
||||
'LOWER(TaxonomyPredicate.value)' => mb_strtolower($splits['predicate']),
|
||||
);
|
||||
$contain['TaxonomyPredicate']['TaxonomyEntry']['conditions'] = array(
|
||||
'LOWER(TaxonomyEntry.value)' => mb_strtolower($splits['value']),
|
||||
$key = 'taxonomies_cache:tagName=' . $tagName . "&" . "metaOnly=$metaOnly" . "&" . "fullTaxonomy=$fullTaxonomy";
|
||||
$model = $this;
|
||||
|
||||
return Cache::remember($key, function () use ($model, $metaOnly, $fullTaxonomy, $splits) {
|
||||
if (isset($splits['value'])) {
|
||||
$contain = array(
|
||||
'TaxonomyPredicate' => array(
|
||||
'TaxonomyEntry' => array()
|
||||
)
|
||||
);
|
||||
if (!$fullTaxonomy) {
|
||||
$contain['TaxonomyPredicate']['conditions'] = array(
|
||||
'LOWER(TaxonomyPredicate.value)' => mb_strtolower($splits['predicate']),
|
||||
);
|
||||
$contain['TaxonomyPredicate']['TaxonomyEntry']['conditions'] = array(
|
||||
'LOWER(TaxonomyEntry.value)' => mb_strtolower($splits['value']),
|
||||
);
|
||||
}
|
||||
$taxonomy = $model->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('LOWER(Taxonomy.namespace)' => mb_strtolower($splits['namespace'])),
|
||||
'contain' => $contain
|
||||
));
|
||||
if ($metaOnly && !empty($taxonomy)) {
|
||||
$taxonomy = array('Taxonomy' => $taxonomy['Taxonomy']);
|
||||
}
|
||||
|
||||
return $taxonomy;
|
||||
} else {
|
||||
$contain = array('TaxonomyPredicate' => array());
|
||||
if (!$fullTaxonomy) {
|
||||
$contain['TaxonomyPredicate']['conditions'] = array(
|
||||
'LOWER(TaxonomyPredicate.value)' => mb_strtolower($splits['predicate'])
|
||||
);
|
||||
}
|
||||
$taxonomy = $model->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('LOWER(Taxonomy.namespace)' => mb_strtolower($splits['namespace'])),
|
||||
'contain' => $contain
|
||||
));
|
||||
if ($metaOnly && !empty($taxonomy)) {
|
||||
$taxonomy = array('Taxonomy' => $taxonomy['Taxonomy']);
|
||||
}
|
||||
|
||||
return $taxonomy;
|
||||
}
|
||||
$taxonomy = $this->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('LOWER(Taxonomy.namespace)' => mb_strtolower($splits['namespace'])),
|
||||
'contain' => $contain
|
||||
));
|
||||
if ($metaOnly && !empty($taxonomy)) {
|
||||
return array('Taxonomy' => $taxonomy['Taxonomy']);
|
||||
}
|
||||
return $taxonomy;
|
||||
} else {
|
||||
$contain = array('TaxonomyPredicate' => array());
|
||||
if (!$fullTaxonomy) {
|
||||
$contain['TaxonomyPredicate']['conditions'] = array(
|
||||
'LOWER(TaxonomyPredicate.value)' => mb_strtolower($splits['predicate'])
|
||||
);
|
||||
}
|
||||
$taxonomy = $this->find('first', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('LOWER(Taxonomy.namespace)' => mb_strtolower($splits['namespace'])),
|
||||
'contain' => $contain
|
||||
));
|
||||
if ($metaOnly && !empty($taxonomy)) {
|
||||
return array('Taxonomy' => $taxonomy['Taxonomy']);
|
||||
}
|
||||
return $taxonomy;
|
||||
}
|
||||
}, 'misp_short');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -270,6 +270,12 @@ Cache::config('_cake_core_', array(
|
|||
'duration' => $duration
|
||||
));
|
||||
|
||||
Cache::config('misp_short', array(
|
||||
'engine' => $engine,
|
||||
'duration' => '1800', // 30 minutes
|
||||
'prefix' => 'misp_cache_short_',
|
||||
));
|
||||
|
||||
/**
|
||||
* Configure the cache for model and datasource caches. This cache configuration
|
||||
* is used to store schema descriptions, and table listings in connections.
|
||||
|
|
Loading…
Reference in New Issue