mirror of https://github.com/MISP/MISP
new: [usage data widget] added a global caching for attribute counts
- counts are too bloody expensive not to do thispull/8902/merge
parent
f02d52b1ab
commit
8246b5b44f
|
@ -16,6 +16,7 @@ class UsageDataWidget
|
||||||
private $Correlation = null;
|
private $Correlation = null;
|
||||||
private $Thread = null;
|
private $Thread = null;
|
||||||
private $AuthKey = null;
|
private $AuthKey = null;
|
||||||
|
private $redis = null;
|
||||||
|
|
||||||
private $validFilterKeys = [
|
private $validFilterKeys = [
|
||||||
'nationality',
|
'nationality',
|
||||||
|
@ -41,8 +42,12 @@ class UsageDataWidget
|
||||||
'Discussion posts'
|
'Discussion posts'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function handler($user, $options = array()){
|
public function handler($user, $options = array()) {
|
||||||
$this->User = ClassRegistry::init('User');
|
$this->User = ClassRegistry::init('User');
|
||||||
|
$this->redis = $this->User->setupRedis();
|
||||||
|
if (!$this->redis) {
|
||||||
|
throw new NotFoundException(__('No redis connection found.'));
|
||||||
|
}
|
||||||
$this->Event = ClassRegistry::init('Event');
|
$this->Event = ClassRegistry::init('Event');
|
||||||
$this->Thread = ClassRegistry::init('Thread');
|
$this->Thread = ClassRegistry::init('Thread');
|
||||||
$this->Correlation = ClassRegistry::init('Correlation');
|
$this->Correlation = ClassRegistry::init('Correlation');
|
||||||
|
@ -203,11 +208,17 @@ class UsageDataWidget
|
||||||
if (!empty($orgIdList)) {
|
if (!empty($orgIdList)) {
|
||||||
$conditions['AND'][] = ['Event.orgc_id IN' => $orgIdList];
|
$conditions['AND'][] = ['Event.orgc_id IN' => $orgIdList];
|
||||||
}
|
}
|
||||||
return $this->Event->Attribute->find('count', [
|
$hash = hash('sha256', json_encode($orgIdList));
|
||||||
'conditions' => $conditions,
|
$count = $this->redis->get('misp:dashboard:attribute_count:' . $hash);
|
||||||
'contain' => ['Event'],
|
if (empty($count)) {
|
||||||
'recursive' => -1
|
$count = $this->Event->Attribute->find('count', [
|
||||||
]);
|
'conditions' => $conditions,
|
||||||
|
'contain' => ['Event'],
|
||||||
|
'recursive' => -1
|
||||||
|
]);
|
||||||
|
$this->redis->setEx('misp:dashboard:attribute_count:' . $hash, 3600, $count);
|
||||||
|
}
|
||||||
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAttributesCountMonth($orgConditions, $orgIdList, $thisMonth)
|
private function getAttributesCountMonth($orgConditions, $orgIdList, $thisMonth)
|
||||||
|
|
Loading…
Reference in New Issue