mirror of https://github.com/MISP/MISP
chg: [internal] Optimise loading attribute histogram
parent
7748598750
commit
bcc499db1e
|
@ -1391,9 +1391,9 @@ class UsersController extends AppController
|
|||
if (!$this->_isSiteAdmin() && !empty(Configure::read('Security.hide_organisation_index_from_users'))) {
|
||||
$org_ids = array($this->Auth->user('org_id'));
|
||||
} else {
|
||||
$org_ids = $this->User->Event->find('list', array(
|
||||
'fields' => array('Event.orgc_id', 'Event.orgc_id'),
|
||||
'group' => array('Event.orgc_id')
|
||||
$org_ids = $this->User->Event->find('column', array(
|
||||
'fields' => array('Event.orgc_id'),
|
||||
'unique' => true,
|
||||
));
|
||||
}
|
||||
$orgs_temp = $this->User->Organisation->find('list', array(
|
||||
|
@ -1440,20 +1440,28 @@ class UsersController extends AppController
|
|||
$temp = $this->User->Event->Attribute->find('all', $params);
|
||||
$temp = Hash::combine($temp, '{n}.Attribute.type', '{n}.0.num_types');
|
||||
$total = 0;
|
||||
foreach ($temp as $k => $v) {
|
||||
if (intval($v) > $max) {
|
||||
$max = intval($v);
|
||||
foreach ($temp as $v) {
|
||||
$v = (int) $v;
|
||||
if ($v > $max) {
|
||||
$max = $v;
|
||||
}
|
||||
$total += intval($v);
|
||||
$total += $v;
|
||||
}
|
||||
$data[$org_id]['data'] = $temp;
|
||||
$data[$org_id]['org_name'] = $org_name;
|
||||
$data[$org_id]['total'] = $total;
|
||||
$data[$org_id] = [
|
||||
'data' => $temp,
|
||||
'org_name' => $org_name,
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
uasort($data, function ($a, $b) {
|
||||
return $b['total'] - $a['total'];
|
||||
});
|
||||
$data = array_values($data);
|
||||
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData($data, $this->response->type());
|
||||
}
|
||||
|
||||
$this->set('data', $data);
|
||||
$this->set('max', $max);
|
||||
$this->set('selectedTypes', $selectedTypes);
|
||||
|
@ -1467,13 +1475,10 @@ class UsersController extends AppController
|
|||
foreach ($sigTypes as $k => $type) {
|
||||
$typeDb[$type] = $colours[$k];
|
||||
}
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData($data, $this->response->type());
|
||||
} else {
|
||||
$this->set('typeDb', $typeDb);
|
||||
$this->set('sigTypes', $sigTypes);
|
||||
$this->layout = 'ajax';
|
||||
}
|
||||
|
||||
$this->set('typeDb', $typeDb);
|
||||
$this->set('sigTypes', $sigTypes);
|
||||
$this->layout = 'ajax';
|
||||
}
|
||||
|
||||
public function terms()
|
||||
|
@ -1812,6 +1817,8 @@ class UsersController extends AppController
|
|||
// shows some statistics about the instance
|
||||
public function statistics($page = 'data')
|
||||
{
|
||||
@session_write_close(); // loading this page can take long time, so we can close session
|
||||
|
||||
$this->set('page', $page);
|
||||
$pages = array('data' => __('Usage data'),
|
||||
'orgs' => __('Organisations'),
|
||||
|
|
|
@ -10,6 +10,7 @@ App::uses('SendEmail', 'Tools');
|
|||
* @property Organisation $Organisation
|
||||
* @property Role $Role
|
||||
* @property UserSetting $UserSetting
|
||||
* @property Event $Event
|
||||
*/
|
||||
class User extends AppModel
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
?>
|
||||
<div class="attributehistogram-legend-line">
|
||||
<div class="attributehistogram-legend-box" style="display: block;float: left;margin: 4px 6px 0 0;background-color:<?php echo $colour; ?>"> </div>
|
||||
<div style="display: inline-block;cursor: pointer;<?php if (in_array($type, $selectedTypes)) echo 'font-weight:bold';?>" role="button" tabindex="0" aria-label="<?php echo __('Toggle histogram');?>" tite="<?php echo __('Toggle histogram');?>" onClick='toggleHistogramType("<?php echo h($type); ?>", [<?php foreach ($selectedTypes as $t) echo '"' . $t . '", ' ?>]);'><?php echo h($type);?></div>
|
||||
<div style="display: inline-block;cursor: pointer;<?php if (in_array($type, $selectedTypes)) echo 'font-weight:bold';?>" role="button" tabindex="0" aria-label="<?php echo __('Toggle histogram');?>" title="<?php echo __('Toggle histogram');?>" onClick='toggleHistogramType("<?php echo h($type); ?>", [<?php foreach ($selectedTypes as $t) echo '"' . $t . '", ' ?>]);'><?php echo h($type);?></div>
|
||||
</div>
|
||||
<?php
|
||||
$cnt++;
|
||||
|
|
Loading…
Reference in New Issue