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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joshtrichards
Copy link
Member

@joshtrichards joshtrichards commented Dec 27, 2024

Summary

Specify default protocol (https://) for the default domains rather than let default handling trigger both http:// and https:// tests.

Reduces network category check time by >20% (#49978) and overall setup check time by ~16% in my test environment.

TODO

  • n/a

Checklist

@joshtrichards joshtrichards added this to the Nextcloud 31 milestone Dec 27, 2024
@joshtrichards joshtrichards requested review from susnux, come-nc, a team, skjnldsv and provokateurin and removed request for a team December 27, 2024 16:05
Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, that only speeds up things when internet connectivity is broken, no?

Okay, read the code, and it’s backwards for protocol I think, it should only check https if http fails.

@come-nc
Copy link
Contributor

come-nc commented Jan 6, 2025

How about:

diff --git a/apps/settings/lib/SetupChecks/InternetConnectivity.php b/apps/settings/lib/SetupChecks/InternetConnectivity.php
index 3a0af06e71b..0b46ac2de5b 100644
--- a/apps/settings/lib/SetupChecks/InternetConnectivity.php
+++ b/apps/settings/lib/SetupChecks/InternetConnectivity.php
@@ -57,17 +57,15 @@ class InternetConnectivity implements ISetupCheck {
         * @param string $site site domain or full URL with http/https protocol
         */
        private function isSiteReachable(string $site): bool {
+               if (preg_match('/^https?:\/\//', $site) !== 1) {
+                       // if there is no protocol, test http:// AND https://
+                       $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',

?

But adding https to the default values would still make sense I suppose.

Specify default protocol (https://) rather than let default handling test both http:// and https://

Signed-off-by: Josh <[email protected]>
@joshtrichards joshtrichards force-pushed the jtr-perf-checks-connectivity-https-proto branch from 2a79fbf to 35cb5d8 Compare January 7, 2025 21:49
@blizzz blizzz mentioned this pull request Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants