Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(settings): Speed up InternetConnectivity setup check #49977

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions apps/settings/lib/SetupChecks/InternetConnectivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ public function run(): SetupResult {
}

$siteArray = $this->config->getSystemValue('connectivity_check_domains', [
'www.nextcloud.com', 'www.startpage.com', 'www.eff.org', 'www.edri.org'
'https://www.nextcloud.com', 'https://www.startpage.com', 'https://www.eff.org', 'https://www.edri.org'
]);

foreach ($siteArray as $site) {
if ($this->isSiteReachable($site)) {
// successful as soon as one connection succeeds
return SetupResult::success();
}
}
Expand All @@ -55,19 +56,18 @@ public function run(): SetupResult {
/**
* Checks if the Nextcloud server can connect to a specific URL
* @param string $site site domain or full URL with http/https protocol
* @return bool success/failure
*/
private function isSiteReachable(string $site): bool {
// if there is no protocol specified, test http:// first then, if necessary, https://
if (preg_match('/^https?:\/\//', $site) !== 1) {
$httpSite = 'http://' . $site . '/';
$httpsSite = 'https://' . $site . '/';
return $this->isSiteReachable($httpSite) || $this->isSiteReachable($httpsSite);
}
try {
$client = $this->clientService->newClient();
// if there is no protocol, test http:// AND https://
if (preg_match('/^https?:\/\//', $site) !== 1) {
$httpSite = 'http://' . $site . '/';
$client->get($httpSite);
$httpsSite = 'https://' . $site . '/';
$client->get($httpsSite);
} else {
$client->get($site);
}
$client->get($site);
} catch (\Exception $e) {
$this->logger->error('Cannot connect to: ' . $site, [
'app' => 'internet_connection_check',
Expand Down
16 changes: 8 additions & 8 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,16 +936,16 @@
*
* Defaults to the following domains:
*
* - www.nextcloud.com
* - www.startpage.com
* - www.eff.org
* - www.edri.org
* - https://www.nextcloud.com
* - https://www.startpage.com
* - https://www.eff.org
* - https://www.edri.org
*/
'connectivity_check_domains' => [
'www.nextcloud.com',
'www.startpage.com',
'www.eff.org',
'www.edri.org'
'https://www.nextcloud.com',
'https://www.startpage.com',
'https://www.eff.org',
'https://www.edri.org'
],

/**
Expand Down
Loading