From b8cbe1571593509bb8aed6de74a83366dfbdc644 Mon Sep 17 00:00:00 2001 From: Thijs Kinkhorst <thijs@kinkhorst.com> Date: Fri, 15 Jul 2016 15:02:32 +0000 Subject: [PATCH] Version checking: do not poll github when running master, and store result in session. --- modules/core/www/frontpage_config.php | 45 ++++++++++++++++----------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/modules/core/www/frontpage_config.php b/modules/core/www/frontpage_config.php index 871c29bdb..0ac8d7c7d 100644 --- a/modules/core/www/frontpage_config.php +++ b/modules/core/www/frontpage_config.php @@ -70,27 +70,34 @@ $allLinks = array( ); SimpleSAML\Module::callHooks('frontpage', $allLinks); -// check for updates -if ($config->getBoolean('admin.checkforupdates', true)) { - $api_url = 'https://api.github.com/repos/simplesamlphp/simplesamlphp/releases'; - $ch = curl_init($api_url.'/latest'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_USERAGENT, 'SimpleSAMLphp'); - curl_setopt($ch, CURLOPT_TIMEOUT, 2); - $response = curl_exec($ch); - - if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) { - $latest = json_decode($response, true); - $current = $config->getVersion(); - if ($current !== 'master' && version_compare($current, ltrim($latest['tag_name'], 'v'), 'lt')) { - $outdated = true; - $warnings[] = array( - '{core:frontpage:warnings_outdated}', - array('%LATEST_URL%' => $latest['html_url']) - ); +// Check for updates. Store the remote result in the session so we +// don't need to fetch it on every access of this page. +$current = $config->getVersion(); +if ($config->getBoolean('admin.checkforupdates', true) && $current !== 'master') { + $latest = $session->getData("core:latest_simplesamlphp_version", "version"); + + if (!$latest) { + $api_url = 'https://api.github.com/repos/simplesamlphp/simplesamlphp/releases'; + $ch = curl_init($api_url.'/latest'); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_USERAGENT, 'SimpleSAMLphp'); + curl_setopt($ch, CURLOPT_TIMEOUT, 2); + $response = curl_exec($ch); + + if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200) { + $latest = json_decode($response, true); + $session->setData("core:latest_simplesamlphp_version", "version", $latest); } + curl_close($ch); + } + + if ($latest && version_compare($current, ltrim($latest['tag_name'], 'v'), 'lt')) { + $outdated = true; + $warnings[] = array( + '{core:frontpage:warnings_outdated}', + array('%LATEST_URL%' => $latest['html_url']) + ); } - curl_close($ch); } $enablematrix = array( -- GitLab