Skip to content

Commit

Permalink
catch nonexistant metrics table on home page
Browse files Browse the repository at this point in the history
  • Loading branch information
themightychris committed Jun 7, 2015
1 parent f4516f0 commit ddd1893
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions php-classes/Gatekeeper/HomeRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit ddd1893

Please sign in to comment.