mirror of https://github.com/MISP/MISP
huge performance increase in generateCount
parent
b314a04e58
commit
e328dc948e
|
@ -305,11 +305,14 @@ class AppController extends Controller {
|
||||||
|
|
||||||
public function generateCount() {
|
public function generateCount() {
|
||||||
if (!self::_isSiteAdmin()) throw new NotFoundException();
|
if (!self::_isSiteAdmin()) throw new NotFoundException();
|
||||||
$this->loadModel('Event');
|
// do one SQL query with the counts
|
||||||
$events = $this->Event->find('all', array('recursive' => 1));
|
// loop over events, update in db
|
||||||
|
$this->loadModel('Attribute');
|
||||||
|
$events = $this->Attribute->query('SELECT event_id, count(event_id) as attribute_count FROM attributes GROUP BY event_id');
|
||||||
foreach ($events as $event) {
|
foreach ($events as $event) {
|
||||||
$event['Event']['attribute_count'] = sizeof($event['Attribute']);
|
$this->Event->read(null, $event['attributes']['event_id']);
|
||||||
$this->Event->save($event);
|
$this->Event->set('attribute_count', $event[0]['attribute_count']);
|
||||||
|
$this->Event->save();
|
||||||
}
|
}
|
||||||
$this->Session->setFlash(__('All done.'));
|
$this->Session->setFlash(__('All done.'));
|
||||||
$this->redirect(array('controller' => 'events', 'action' => 'index', 'admin' => false));
|
$this->redirect(array('controller' => 'events', 'action' => 'index', 'admin' => false));
|
||||||
|
|
Loading…
Reference in New Issue