Skip to content

Commit d93b001

Browse files
authored
Merge pull request #26811 from nextcloud/enh/lookupserver/do_not_send_if_not_needed
Do not try to contact lookup server if not needed
2 parents 48f0515 + 758a662 commit d93b001

7 files changed

Lines changed: 132 additions & 3 deletions

File tree

apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,23 @@ protected function run($argument): void {
152152

153153
try {
154154
if (count($data) === 1) {
155-
// No public data, just the federation Id
155+
$dataOnLookupServer = $this->config->getUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '0') === '1';
156+
157+
if (!$dataOnLookupServer) {
158+
// We never send data to the lookupserver so no need to delete it
159+
return;
160+
}
161+
162+
// There is data on the lookup server so we must delete it
156163
$client->delete($this->lookupServer,
157164
[
158165
'body' => json_encode($signedData),
159166
'timeout' => 10,
160167
'connect_timeout' => 3,
161168
]
162169
);
170+
171+
$this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '0');
163172
} else {
164173
$client->post($this->lookupServer,
165174
[
@@ -168,6 +177,7 @@ protected function run($argument): void {
168177
'connect_timeout' => 3,
169178
]
170179
);
180+
$this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '1');
171181
}
172182

173183
// Reset retry counter
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2021 Roeland Jago Douma <roeland@famdouma.nl>
7+
*
8+
* @author Roeland Jago Douma <roeland@famdouma.nl>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OC\Core\BackgroundJobs;
28+
29+
use OC\BackgroundJob\QueuedJob;
30+
use OCP\IConfig;
31+
use OCP\IUser;
32+
use OCP\IUserManager;
33+
34+
class LookupServerSendCheckBackgroundJob extends QueuedJob {
35+
36+
/** @var IConfig */
37+
protected $config;
38+
/** @var IUserManager */
39+
private $userManager;
40+
41+
public function __construct(IConfig $config, IUserManager $userManager) {
42+
$this->config = $config;
43+
$this->userManager = $userManager;
44+
}
45+
46+
public function run($arguments) {
47+
$this->userManager->callForSeenUsers(function (IUser $user) {
48+
$this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '1');
49+
});
50+
}
51+
}

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@
792792
'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => $baseDir . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php',
793793
'OC\\Core\\BackgroundJobs\\CheckForUserCertificates' => $baseDir . '/core/BackgroundJobs/CheckForUserCertificates.php',
794794
'OC\\Core\\BackgroundJobs\\CleanupLoginFlowV2' => $baseDir . '/core/BackgroundJobs/CleanupLoginFlowV2.php',
795+
'OC\\Core\\BackgroundJobs\\LookupServerSendCheckBackgroundJob' => $baseDir . '/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php',
795796
'OC\\Core\\Command\\App\\CheckCode' => $baseDir . '/core/Command/App/CheckCode.php',
796797
'OC\\Core\\Command\\App\\Disable' => $baseDir . '/core/Command/App/Disable.php',
797798
'OC\\Core\\Command\\App\\Enable' => $baseDir . '/core/Command/App/Enable.php',
@@ -1304,6 +1305,7 @@
13041305
'OC\\Repair\\NC20\\ShippedDashboardEnable' => $baseDir . '/lib/private/Repair/NC20/ShippedDashboardEnable.php',
13051306
'OC\\Repair\\NC21\\AddCheckForUserCertificatesJob' => $baseDir . '/lib/private/Repair/NC21/AddCheckForUserCertificatesJob.php',
13061307
'OC\\Repair\\NC21\\ValidatePhoneNumber' => $baseDir . '/lib/private/Repair/NC21/ValidatePhoneNumber.php',
1308+
'OC\\Repair\\NC22\\LookupServerSendCheck' => $baseDir . '/lib/private/Repair/NC22/LookupServerSendCheck.php',
13071309
'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php',
13081310
'OC\\Repair\\Owncloud\\CleanPreviews' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviews.php',
13091311
'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
821821
'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php',
822822
'OC\\Core\\BackgroundJobs\\CheckForUserCertificates' => __DIR__ . '/../../..' . '/core/BackgroundJobs/CheckForUserCertificates.php',
823823
'OC\\Core\\BackgroundJobs\\CleanupLoginFlowV2' => __DIR__ . '/../../..' . '/core/BackgroundJobs/CleanupLoginFlowV2.php',
824+
'OC\\Core\\BackgroundJobs\\LookupServerSendCheckBackgroundJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php',
824825
'OC\\Core\\Command\\App\\CheckCode' => __DIR__ . '/../../..' . '/core/Command/App/CheckCode.php',
825826
'OC\\Core\\Command\\App\\Disable' => __DIR__ . '/../../..' . '/core/Command/App/Disable.php',
826827
'OC\\Core\\Command\\App\\Enable' => __DIR__ . '/../../..' . '/core/Command/App/Enable.php',
@@ -1333,6 +1334,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
13331334
'OC\\Repair\\NC20\\ShippedDashboardEnable' => __DIR__ . '/../../..' . '/lib/private/Repair/NC20/ShippedDashboardEnable.php',
13341335
'OC\\Repair\\NC21\\AddCheckForUserCertificatesJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC21/AddCheckForUserCertificatesJob.php',
13351336
'OC\\Repair\\NC21\\ValidatePhoneNumber' => __DIR__ . '/../../..' . '/lib/private/Repair/NC21/ValidatePhoneNumber.php',
1337+
'OC\\Repair\\NC22\\LookupServerSendCheck' => __DIR__ . '/../../..' . '/lib/private/Repair/NC22/LookupServerSendCheck.php',
13361338
'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php',
13371339
'OC\\Repair\\Owncloud\\CleanPreviews' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/CleanPreviews.php',
13381340
'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php',

lib/private/Repair.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
use OC\Repair\ClearGeneratedAvatarCache;
4646
use OC\Repair\Collation;
4747
use OC\Repair\MoveUpdaterStepFile;
48+
use OC\Repair\NC22\LookupServerSendCheck;
4849
use OC\Repair\Owncloud\CleanPreviews;
4950
use OC\Repair\NC11\FixMountStorages;
5051
use OC\Repair\Owncloud\MoveAvatars;
@@ -199,7 +200,8 @@ public static function getRepairSteps() {
199200
\OC::$server->get(ShippedDashboardEnable::class),
200201
\OC::$server->get(AddBruteForceCleanupJob::class),
201202
\OC::$server->get(AddCheckForUserCertificatesJob::class),
202-
\OC::$server->get(RepairDavShares::class)
203+
\OC::$server->get(RepairDavShares::class),
204+
\OC::$server->get(LookupServerSendCheck::class),
203205
];
204206
}
205207

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2021 Roeland Jago Douma <roeland@famdouma.nl>
7+
*
8+
* @author Roeland Jago Douma <roeland@famdouma.nl>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OC\Repair\NC22;
28+
29+
use OC\Core\BackgroundJobs\LookupServerSendCheckBackgroundJob;
30+
use OCP\BackgroundJob\IJobList;
31+
use OCP\IConfig;
32+
use OCP\Migration\IOutput;
33+
use OCP\Migration\IRepairStep;
34+
35+
class LookupServerSendCheck implements IRepairStep {
36+
37+
/** @var IJobList */
38+
private $jobList;
39+
40+
/** @var IConfig */
41+
private $config;
42+
43+
public function __construct(IJobList $jobList, IConfig $config) {
44+
$this->jobList = $jobList;
45+
$this->config = $config;
46+
}
47+
48+
public function getName(): string {
49+
return 'Add background job to set the lookup server share state for users';
50+
}
51+
52+
private function shouldRun(): bool {
53+
$versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0');
54+
55+
// was added to 22.0.0.3
56+
return version_compare($versionFromBeforeUpdate, '22.0.0.3', '<');
57+
}
58+
59+
public function run(IOutput $output): void {
60+
$this->jobList->add(LookupServerSendCheckBackgroundJob::class);
61+
}
62+
}

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
3131
// when updating major/minor version number.
3232

33-
$OC_Version = [22, 0, 0, 2];
33+
$OC_Version = [22, 0, 0, 3];
3434

3535
// The human readable string
3636
$OC_VersionString = '22.0.0 alpha';

0 commit comments

Comments
 (0)