mirror of https://github.com/MISP/MISP
fix: [performance] notifications lookup on each UI page load was slow
- introduced a major bottleneck on large instances - massively reduced the load times for pages that warranted nonepull/5245/head
parent
e6b8970b0f
commit
cee439dc80
|
@ -463,7 +463,11 @@ class AppController extends Controller
|
|||
}
|
||||
|
||||
$this->set('loggedInUserName', $this->__convertEmailToName($this->Auth->user('email')));
|
||||
$notifications = $this->{$this->modelClass}->populateNotifications($this->Auth->user());
|
||||
if ($this->request->params['controller'] === 'users' && $this->request->params['action'] === 'dashboard') {
|
||||
$notifications = $this->{$this->modelClass}->populateNotifications($this->Auth->user());
|
||||
} else {
|
||||
$notifications = $this->{$this->modelClass}->populateNotifications($this->Auth->user(), 'fast');
|
||||
}
|
||||
$this->set('notifications', $notifications);
|
||||
$this->ACL->checkAccess($this->Auth->user(), Inflector::variable($this->request->params['controller']), $this->action);
|
||||
}
|
||||
|
|
|
@ -1795,44 +1795,47 @@ class AppModel extends Model
|
|||
return $updates;
|
||||
}
|
||||
|
||||
|
||||
public function populateNotifications($user)
|
||||
public function populateNotifications($user, $mode = 'full')
|
||||
{
|
||||
$notifications = array();
|
||||
$proposalCount = $this->_getProposalCount($user);
|
||||
$notifications['total'] = 0;
|
||||
$notifications['proposalCount'] = $proposalCount[0];
|
||||
$notifications['total'] += $proposalCount[0];
|
||||
$notifications['proposalEventCount'] = $proposalCount[1];
|
||||
list($notifications['proposalCount'], $notifications['proposalEventCount']) = $this->_getProposalCount($user, $mode);
|
||||
$notifications['total'] = $notifications['proposalCount'];
|
||||
if (Configure::read('MISP.delegation')) {
|
||||
$delegationCount = $this->_getDelegationCount($user);
|
||||
$notifications['total'] += $delegationCount;
|
||||
$notifications['delegationCount'] = $delegationCount;
|
||||
$notifications['delegationCount'] = $this->_getDelegationCount($user);
|
||||
$notifications['total'] += $notifications['delegationCount'];
|
||||
}
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
|
||||
private function _getProposalCount($user)
|
||||
// if not using $mode === 'full', simply check if an entry exists. We really don't care about the real count for the top menu.
|
||||
private function _getProposalCount($user, $mode = 'full')
|
||||
{
|
||||
$this->ShadowAttribute = ClassRegistry::init('ShadowAttribute');
|
||||
$this->ShadowAttribute->recursive = -1;
|
||||
$shadowAttributes = $this->ShadowAttribute->find('all', array(
|
||||
$results[0] = $this->ShadowAttribute->find(
|
||||
'count',
|
||||
array(
|
||||
'recursive' => -1,
|
||||
'fields' => array('event_id', 'event_org_id'),
|
||||
'conditions' => array(
|
||||
'ShadowAttribute.event_org_id' => $user['org_id'],
|
||||
'ShadowAttribute.deleted' => 0,
|
||||
)));
|
||||
$results = array();
|
||||
$eventIds = array();
|
||||
$results[0] = count($shadowAttributes);
|
||||
foreach ($shadowAttributes as $sa) {
|
||||
if (!in_array($sa['ShadowAttribute']['event_id'], $eventIds)) {
|
||||
$eventIds[] = $sa['ShadowAttribute']['event_id'];
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
if ($mode === 'full') {
|
||||
$results[1] = $this->ShadowAttribute->find(
|
||||
'count',
|
||||
array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array(
|
||||
'ShadowAttribute.event_org_id' => $user['org_id'],
|
||||
'ShadowAttribute.deleted' => 0,
|
||||
),
|
||||
'fields' => 'distinct event_id'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$results[1] = $results[0];
|
||||
}
|
||||
$results[1] = count($eventIds);
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
@ -1840,10 +1843,8 @@ class AppModel extends Model
|
|||
{
|
||||
$this->EventDelegation = ClassRegistry::init('EventDelegation');
|
||||
$delegations = $this->EventDelegation->find('count', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array(
|
||||
'EventDelegation.org_id' => $user['org_id']
|
||||
)
|
||||
'recursive' => -1,
|
||||
'conditions' => array('EventDelegation.org_id' => $user['org_id'])
|
||||
));
|
||||
return $delegations;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ class ShadowAttribute extends AppModel
|
|||
|
||||
public $name = 'ShadowAttribute'; // TODO general
|
||||
|
||||
public $recursive = -1;
|
||||
|
||||
public $actsAs = array(
|
||||
'SysLogLogable.SysLogLogable' => array( // TODO Audit, logable
|
||||
'userModel' => 'User',
|
||||
|
@ -508,7 +510,12 @@ class ShadowAttribute extends AppModel
|
|||
|
||||
public function getEventContributors($id)
|
||||
{
|
||||
$orgs = $this->find('all', array('fields' => array('DISTINCT(org_id)'), 'conditions' => array('event_id' => $id), 'order' => false));
|
||||
$orgs = $this->find('all', array('fields' => array(
|
||||
'DISTINCT(ShadowAttribute.org_id)'),
|
||||
'conditions' => array('event_id' => $id),
|
||||
'recursive' => -1,
|
||||
'order' => false
|
||||
));
|
||||
$org_ids = array();
|
||||
$this->Organisation = ClassRegistry::init('Organisation');
|
||||
foreach ($orgs as $org) {
|
||||
|
|
Loading…
Reference in New Issue