From e14b54d71219151c5f477854b3a3169783705aae Mon Sep 17 00:00:00 2001 From: Jeffrey Lembeck Date: Wed, 25 May 2022 09:09:14 -0700 Subject: [PATCH] fix(testlog): make test history more resilient This is a test. We're trying to figure out why test history keeps going down bigger queries or queries in general. This involves removing the time limit on the page for logged in users while simultaneously setting a large timeout for the backend calls. We're also making the query and things around it a bit more resilient --- www/src/CPClient.php | 16 +++++++++++----- www/testlog.php | 7 ++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/www/src/CPClient.php b/www/src/CPClient.php index 1cf7c6ba13..39d24f2c3a 100644 --- a/www/src/CPClient.php +++ b/www/src/CPClient.php @@ -30,7 +30,10 @@ class CPClient public function __construct(string $host, array $options = []) { $auth_client_options = $options['auth_client_options'] ?? array(); - $graphql_client_options = array(); + $graphql_client_options = array( + 'timeout' => 30, + 'connect_timeout' => 30 + ); $this->client_id = $auth_client_options['client_id'] ?? null; $this->client_secret = $auth_client_options['client_secret'] ?? null; @@ -510,12 +513,15 @@ public function getTestHistory(int $days = 1): array 'viewHours' => $view_hours ]; - $test_history = []; $response = $this->graphql_client->runQuery($gql, true, $variables); $data = $response->getData()['wptTestHistory']; - foreach ($data as $record) { - $test_history[] = new TestRecord($record); - } + $test_history = array_map(function ($record): TestRecord { + try { + return new TestRecord($record); + } catch (\Exception $e) { + error_log($e->getMessage()); + } + }, $data); return $test_history; } } diff --git a/www/testlog.php b/www/testlog.php index 11a6704088..e30b8165d8 100644 --- a/www/testlog.php +++ b/www/testlog.php @@ -6,7 +6,9 @@ use WebPageTest\Util; -if ($admin || $privateInstall) { +$is_logged_in = Util::getSetting('cp_auth') && (!is_null($request_context->getClient()) && $request_context->getClient()->isAuthenticated()); + +if ($admin || $privateInstall || $is_logged_in) { set_time_limit(0); } else { set_time_limit(60); @@ -18,14 +20,13 @@ } $test_history = []; -$is_logged_in = Util::getSetting('cp_auth') && (!is_null($request_context->getClient()) && $request_context->getClient()->isAuthenticated()); $days = (int)$_GET["days"]; if ($is_logged_in) { $test_history = $request_context->getClient()->getTestHistory($days); } -// Redirect logged-in users to the hosted test history if one is configured +// Redirect logged-in saml users to the hosted test history if one is configured if (!$is_logged_in && (isset($USER_EMAIL) && Util::getSetting('history_url') && !isset($_REQUEST['local']))) { header('Location: ' . Util::getSetting('history_url')); exit;