]> source.dussan.org Git - nextcloud-server.git/commitdiff
Do not try to contact lookup server if not needed 26824/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Wed, 28 Apr 2021 12:25:17 +0000 (14:25 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 29 Apr 2021 07:23:02 +0000 (09:23 +0200)
In some cases (for example you never send data to the lookup server)
there is no need for this job to even try.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php
core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php [new file with mode: 0644]
lib/composer/composer/autoload_classmap.php
lib/composer/composer/autoload_static.php
lib/private/Repair.php
lib/private/Repair/NC22/LookupServerSendCheck.php [new file with mode: 0644]
version.php

index 272d66e94919868d59f178248047a7e76cb44e33..fed4aa7fec6737fbe41ddaa2ee587ea78b3fcab8 100644 (file)
@@ -152,7 +152,14 @@ class RetryJob extends Job {
 
                try {
                        if (count($data) === 1) {
-                               // No public data, just the federation Id
+                               $dataOnLookupServer = $this->config->getUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '0') === '1';
+
+                               if (!$dataOnLookupServer) {
+                                       // We never send data to the lookupserver so no need to delete it
+                                       return;
+                               }
+
+                               // There is data on the lookup server so we must delete it
                                $client->delete($this->lookupServer,
                                        [
                                                'body' => json_encode($signedData),
@@ -160,6 +167,8 @@ class RetryJob extends Job {
                                                'connect_timeout' => 3,
                                        ]
                                );
+
+                               $this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '0');
                        } else {
                                $client->post($this->lookupServer,
                                        [
@@ -168,6 +177,7 @@ class RetryJob extends Job {
                                                'connect_timeout' => 3,
                                        ]
                                );
+                               $this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '1');
                        }
 
                        // Reset retry counter
diff --git a/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php b/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php
new file mode 100644 (file)
index 0000000..c6bd3c1
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2021 Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Core\BackgroundJobs;
+
+use OC\BackgroundJob\QueuedJob;
+use OCP\IConfig;
+use OCP\IUser;
+use OCP\IUserManager;
+
+class LookupServerSendCheckBackgroundJob extends QueuedJob {
+
+       /** @var IConfig */
+       protected $config;
+       /** @var IUserManager */
+       private $userManager;
+
+       public function __construct(IConfig $config, IUserManager $userManager) {
+               $this->config = $config;
+               $this->userManager = $userManager;
+       }
+
+       public function run($arguments) {
+               $this->userManager->callForSeenUsers(function (IUser $user) {
+                       $this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '1');
+               });
+       }
+}
index 0e64da47846afc8f270c608f71969e63e1993ee5..c829d4fde0e2bf6433683ebd70666c2775dce0d4 100644 (file)
@@ -770,6 +770,7 @@ return array(
     'OC\\Core\\Application' => $baseDir . '/core/Application.php',
     'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => $baseDir . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php',
     'OC\\Core\\BackgroundJobs\\CleanupLoginFlowV2' => $baseDir . '/core/BackgroundJobs/CleanupLoginFlowV2.php',
+    'OC\\Core\\BackgroundJobs\\LookupServerSendCheckBackgroundJob' => $baseDir . '/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php',
     'OC\\Core\\Command\\App\\CheckCode' => $baseDir . '/core/Command/App/CheckCode.php',
     'OC\\Core\\Command\\App\\Disable' => $baseDir . '/core/Command/App/Disable.php',
     'OC\\Core\\Command\\App\\Enable' => $baseDir . '/core/Command/App/Enable.php',
@@ -1263,6 +1264,7 @@ return array(
     'OC\\Repair\\NC20\\EncryptionLegacyCipher' => $baseDir . '/lib/private/Repair/NC20/EncryptionLegacyCipher.php',
     'OC\\Repair\\NC20\\EncryptionMigration' => $baseDir . '/lib/private/Repair/NC20/EncryptionMigration.php',
     'OC\\Repair\\NC20\\ShippedDashboardEnable' => $baseDir . '/lib/private/Repair/NC20/ShippedDashboardEnable.php',
+    'OC\\Repair\\NC22\\LookupServerSendCheck' => $baseDir . '/lib/private/Repair/NC22/LookupServerSendCheck.php',
     'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php',
     'OC\\Repair\\Owncloud\\CleanPreviews' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviews.php',
     'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php',
index 13fb59ddfceb38604366e8dd0f188e35730d14e2..2f2d28c2503bcb110bcefc80fb94917fb792ca02 100644 (file)
@@ -799,6 +799,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
         'OC\\Core\\Application' => __DIR__ . '/../../..' . '/core/Application.php',
         'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php',
         'OC\\Core\\BackgroundJobs\\CleanupLoginFlowV2' => __DIR__ . '/../../..' . '/core/BackgroundJobs/CleanupLoginFlowV2.php',
+        'OC\\Core\\BackgroundJobs\\LookupServerSendCheckBackgroundJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php',
         'OC\\Core\\Command\\App\\CheckCode' => __DIR__ . '/../../..' . '/core/Command/App/CheckCode.php',
         'OC\\Core\\Command\\App\\Disable' => __DIR__ . '/../../..' . '/core/Command/App/Disable.php',
         'OC\\Core\\Command\\App\\Enable' => __DIR__ . '/../../..' . '/core/Command/App/Enable.php',
@@ -1292,6 +1293,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
         'OC\\Repair\\NC20\\EncryptionLegacyCipher' => __DIR__ . '/../../..' . '/lib/private/Repair/NC20/EncryptionLegacyCipher.php',
         'OC\\Repair\\NC20\\EncryptionMigration' => __DIR__ . '/../../..' . '/lib/private/Repair/NC20/EncryptionMigration.php',
         'OC\\Repair\\NC20\\ShippedDashboardEnable' => __DIR__ . '/../../..' . '/lib/private/Repair/NC20/ShippedDashboardEnable.php',
+        'OC\\Repair\\NC22\\LookupServerSendCheck' => __DIR__ . '/../../..' . '/lib/private/Repair/NC22/LookupServerSendCheck.php',
         'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php',
         'OC\\Repair\\Owncloud\\CleanPreviews' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/CleanPreviews.php',
         'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php',
index cc477465a8e2f273db88509a2e3edbca14bebf5d..1bf6e2fa964a1c770eb94dcc2fea2d98b12d6552 100644 (file)
@@ -42,6 +42,7 @@ use OC\Repair\ClearFrontendCaches;
 use OC\Repair\ClearGeneratedAvatarCache;
 use OC\Repair\Collation;
 use OC\Repair\MoveUpdaterStepFile;
+use OC\Repair\NC22\LookupServerSendCheck;
 use OC\Repair\Owncloud\CleanPreviews;
 use OC\Repair\NC11\FixMountStorages;
 use OC\Repair\Owncloud\MoveAvatars;
@@ -183,7 +184,8 @@ class Repair implements IOutput {
                        \OC::$server->query(EncryptionLegacyCipher::class),
                        \OC::$server->query(EncryptionMigration::class),
                        \OC::$server->get(ShippedDashboardEnable::class),
-                       \OC::$server->get(RepairDavShares::class)
+                       \OC::$server->get(RepairDavShares::class),
+                       \OC::$server->get(LookupServerSendCheck::class),
                ];
        }
 
diff --git a/lib/private/Repair/NC22/LookupServerSendCheck.php b/lib/private/Repair/NC22/LookupServerSendCheck.php
new file mode 100644 (file)
index 0000000..44fa4ed
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2021 Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Repair\NC22;
+
+use OC\Core\BackgroundJobs\LookupServerSendCheckBackgroundJob;
+use OCP\BackgroundJob\IJobList;
+use OCP\IConfig;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
+
+class LookupServerSendCheck implements IRepairStep {
+
+       /** @var IJobList */
+       private $jobList;
+
+       /** @var IConfig */
+       private $config;
+
+       public function __construct(IJobList $jobList, IConfig $config) {
+               $this->jobList = $jobList;
+               $this->config = $config;
+       }
+
+       public function getName(): string {
+               return 'Add background job to set the lookup server share state for users';
+       }
+
+       private function shouldRun(): bool {
+               $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0');
+
+               // was added to 22.0.0.3
+               return version_compare($versionFromBeforeUpdate, '20.0.9.2', '<') &&
+                       version_compare($versionFromBeforeUpdate, '20.0.0.0', '>');
+       }
+
+       public function run(IOutput $output): void {
+               $this->jobList->add(LookupServerSendCheckBackgroundJob::class);
+       }
+}
index 1d34c9b2339e2e32ece78465f329a14be5d5043f..7506e18c49568babe2c8677e56655adf246a1647 100644 (file)
@@ -29,7 +29,7 @@
 // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
 // when updating major/minor version number.
 
-$OC_Version = [20, 0, 9, 1];
+$OC_Version = [20, 0, 9, 2];
 
 // The human readable string
 $OC_VersionString = '20.0.9';