From 355abc05eb0348fe03e9a83a52c1af4f14ed5485 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Mon, 4 Jan 2021 18:29:32 +0100 Subject: [PATCH] chg: [internal] Small optimisation for filterEventIds --- app/Lib/Dashboard/CsseCovidTrendsWidget.php | 2 +- app/Model/Event.php | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/Lib/Dashboard/CsseCovidTrendsWidget.php b/app/Lib/Dashboard/CsseCovidTrendsWidget.php index f9c9ef279..aaf446f9e 100644 --- a/app/Lib/Dashboard/CsseCovidTrendsWidget.php +++ b/app/Lib/Dashboard/CsseCovidTrendsWidget.php @@ -55,7 +55,7 @@ class CsseCovidTrendsWidget 'date' => (empty($options['timeframe']) ? 10 : $options['timeframe']) . 'd' ); $eventIds = $this->Event->filterEventIds($user, $params); - $eventIds = array_reverse(array_values($eventIds)); + $eventIds = array_reverse($eventIds); $data = array(); if (empty($options['type'])) { $options['type'] = 'confirmed'; diff --git a/app/Model/Event.php b/app/Model/Event.php index ab2ac7e7d..926c48c08 100755 --- a/app/Model/Event.php +++ b/app/Model/Event.php @@ -1691,6 +1691,12 @@ class Event extends AppModel return $tempConditions; } + /** + * @param array $user + * @param array $params + * @param int $result_count + * @return array Event IDs, when `include_attribute_count` is enabled, then it is Event ID => Attribute count + */ public function filterEventIds($user, &$params = array(), &$result_count = 0) { $conditions = $this->createEventConditions($user); @@ -1774,14 +1780,9 @@ class Event extends AppModel } } } - $fields = array('Event.id'); - if (!empty($params['include_attribute_count'])) { - $fields[] = 'Event.attribute_count'; - } $find_params = array( 'conditions' => $conditions, 'recursive' => -1, - 'fields' => $fields ); if (isset($params['order'])) { $find_params['order'] = $params['order']; @@ -1794,7 +1795,13 @@ class Event extends AppModel $find_params['page'] = $params['page']; } } - $results = $this->find('list', $find_params); + if (!empty($params['include_attribute_count'])) { + $find_params['fields'] = array('Event.id', 'Event.attribute_count'); + $results = $this->find('list', $find_params); + } else { + $find_params['fields'] = array('Event.id'); + $results = $this->find('column', $find_params); + } if (!isset($params['limit'])) { $result_count = count($results); }