]> git.mxchange.org Git - friendica.git/commitdiff
Reduce config->set() load for worker executions
authorPhilipp <admin@philipp.info>
Tue, 3 Jan 2023 22:55:51 +0000 (23:55 +0100)
committerPhilipp <admin@philipp.info>
Tue, 3 Jan 2023 23:25:15 +0000 (00:25 +0100)
src/App/BaseURL.php
tests/src/Util/BaseURLTest.php

index 20fd54916de153aa25dc0b29c25db450114a2f46..89dded300289d798c63a0693fea63d6e54f073f9 100644 (file)
@@ -175,6 +175,7 @@ class BaseURL
                $currHostname  = $this->hostname;
                $currSSLPolicy = $this->sslPolicy;
                $currURLPath   = $this->urlPath;
+               $currUrl       = $this->url;
 
                if (!empty($hostname) && $hostname !== $this->hostname) {
                        if ($this->config->set('config', 'hostname', $hostname)) {
@@ -207,16 +208,18 @@ class BaseURL
                }
 
                $this->determineBaseUrl();
-               if (!$this->config->set('system', 'url', $this->url)) {
-                       $this->hostname  = $currHostname;
-                       $this->sslPolicy = $currSSLPolicy;
-                       $this->urlPath   = $currURLPath;
-                       $this->determineBaseUrl();
+               if ($this->url !== $currUrl) {
+                       if (!$this->config->set('system', 'url', $this->url)) {
+                               $this->hostname  = $currHostname;
+                               $this->sslPolicy = $currSSLPolicy;
+                               $this->urlPath   = $currURLPath;
+                               $this->determineBaseUrl();
 
-                       $this->config->set('config', 'hostname', $this->hostname);
-                       $this->config->set('system', 'ssl_policy', $this->sslPolicy);
-                       $this->config->set('system', 'urlpath', $this->urlPath);
-                       return false;
+                               $this->config->set('config', 'hostname', $this->hostname);
+                               $this->config->set('system', 'ssl_policy', $this->sslPolicy);
+                               $this->config->set('system', 'urlpath', $this->urlPath);
+                               return false;
+                       }
                }
 
                return true;
index 0be83be0a7f2faf457e4455c10143bc208c3e5f3..e108385f055b485436b51b3ebe227f24386fbef9 100644 (file)
@@ -231,6 +231,21 @@ class BaseURLTest extends MockedTest
        public function dataSave()
        {
                return [
+                       'no_change' => [
+                               'input' => [
+                                       'hostname'  => 'friendica.local',
+                                       'urlPath'   => 'path',
+                                       'sslPolicy' => BaseURL::SSL_POLICY_FULL,
+                                       'url'       => 'https://friendica.local/path',
+                                       'force_ssl' => true,
+                               ],
+                               'save' => [
+                                       'hostname'  => 'friendica.local',
+                                       'urlPath'   => 'path',
+                                       'sslPolicy' => BaseURL::SSL_POLICY_FULL,
+                               ],
+                               'url' => 'https://friendica.local/path',
+                       ],
                        'default' => [
                                'input' => [
                                        'hostname'  => 'friendica.old',
@@ -324,19 +339,21 @@ class BaseURLTest extends MockedTest
 
                $baseUrl = new BaseURL($configMock, []);
 
-               if (isset($save['hostname'])) {
+               if (isset($save['hostname']) && ($save['hostname'] !== $input['hostname'])) {
                        $configMock->shouldReceive('set')->with('config', 'hostname', $save['hostname'])->andReturn(true)->once();
                }
 
-               if (isset($save['urlPath'])) {
+               if (isset($save['urlPath']) && ($save['urlPath'] !== $input['urlPath'])) {
                        $configMock->shouldReceive('set')->with('system', 'urlpath', $save['urlPath'])->andReturn(true)->once();
                }
 
-               if (isset($save['sslPolicy'])) {
+               if (isset($save['sslPolicy']) && ($save['sslPolicy'] !== $input['sslPolicy'])) {
                        $configMock->shouldReceive('set')->with('system', 'ssl_policy', $save['sslPolicy'])->andReturn(true)->once();
                }
 
-               $configMock->shouldReceive('set')->with('system', 'url', $url)->andReturn(true)->once();
+               if ($input['url'] !== $url) {
+                       $configMock->shouldReceive('set')->with('system', 'url', $url)->andReturn(true)->once();
+               }
 
                $baseUrl->save($save['hostname'], $save['sslPolicy'], $save['urlPath']);
 
@@ -362,19 +379,21 @@ class BaseURLTest extends MockedTest
 
                $baseUrl = new BaseURL($configMock, []);
 
-               if (isset($save['hostname'])) {
+               if (isset($save['hostname']) && ($save['hostname'] !== $input['hostname'])) {
                        $configMock->shouldReceive('set')->with('config', 'hostname', $save['hostname'])->andReturn(true)->once();
                }
 
-               if (isset($save['urlPath'])) {
+               if (isset($save['urlPath']) && ($save['urlPath'] !== $input['urlPath'])) {
                        $configMock->shouldReceive('set')->with('system', 'urlpath', $save['urlPath'])->andReturn(true)->once();
                }
 
-               if (isset($save['sslPolicy'])) {
+               if (isset($save['sslPolicy']) && ($save['sslPolicy'] !== $input['sslPolicy'])) {
                        $configMock->shouldReceive('set')->with('system', 'ssl_policy', $save['sslPolicy'])->andReturn(true)->once();
                }
 
-               $configMock->shouldReceive('set')->with('system', 'url', $url)->andReturn(true)->once();
+               if ($input['url'] !== $url) {
+                       $configMock->shouldReceive('set')->with('system', 'url', $url)->andReturn(true)->once();
+               }
 
                $baseUrl->saveByURL($url);