From ddd189311edb5d408233ad0c67ad6880069bb762 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sun, 7 Jun 2015 16:19:23 -0400 Subject: [PATCH] catch nonexistant metrics table on home page --- php-classes/Gatekeeper/HomeRequestHandler.php | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/php-classes/Gatekeeper/HomeRequestHandler.php b/php-classes/Gatekeeper/HomeRequestHandler.php index 5b9defa..e876fd6 100644 --- a/php-classes/Gatekeeper/HomeRequestHandler.php +++ b/php-classes/Gatekeeper/HomeRequestHandler.php @@ -22,22 +22,26 @@ public static function handleRequest() { // get request totals for trailing week if (false === ($weeklyRequestsByEndpoint = Cache::fetch('endpoints-requests-week'))) { - $weeklyRequestsByEndpoint = array_map('intval', DB::valuesTable( - 'EndpointID', - 'requests', - 'SELECT' - .' SUBSTRING_INDEX(@context := SUBSTRING_INDEX(`Key`, "/", 2), "/", -1) AS EndpointID,' - .' SUM(Value) AS requests' - .' FROM `%s`' - .' WHERE' - .' `Timestamp` BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 WEEK) AND CURRENT_TIMESTAMP AND ' - .' `Key` LIKE "endpoints/%%" AND' - .' `Key` REGEXP "^endpoints/[[:digit:]]+/requests$"' - .' GROUP BY EndpointID', - [ - MetricSample::$tableName - ] - )); + try { + $weeklyRequestsByEndpoint = array_map('intval', DB::valuesTable( + 'EndpointID', + 'requests', + 'SELECT' + .' SUBSTRING_INDEX(@context := SUBSTRING_INDEX(`Key`, "/", 2), "/", -1) AS EndpointID,' + .' SUM(Value) AS requests' + .' FROM `%s`' + .' WHERE' + .' `Timestamp` BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 WEEK) AND CURRENT_TIMESTAMP AND ' + .' `Key` LIKE "endpoints/%%" AND' + .' `Key` REGEXP "^endpoints/[[:digit:]]+/requests$"' + .' GROUP BY EndpointID', + [ + MetricSample::$tableName + ] + )); + } catch (TableNotFoundException $e) { + $weeklyRequestsByEndpoint = []; + } Cache::store('endpoints-requests-week', $weeklyRequestsByEndpoint, static::$popularityTTL); }