Browse Source
fix(caldav): automatically delete outdated scheduling objects
fix(caldav): automatically delete outdated scheduling objects
Signed-off-by: Anna Larch <anna@nextcloud.com>pull/45235/head
12 changed files with 176 additions and 0 deletions
-
2apps/dav/composer/composer/autoload_classmap.php
-
2apps/dav/composer/composer/autoload_static.php
-
35apps/dav/lib/BackgroundJob/DeleteOutdatedSchedulingObjects.php
-
38apps/dav/lib/CalDAV/CalDavBackend.php
-
38apps/dav/lib/Migration/DeleteSchedulingObjects.php
-
1apps/dav/lib/Migration/Version1004Date20170825134824.php
-
1apps/settings/composer/composer/autoload_classmap.php
-
1apps/settings/composer/composer/autoload_static.php
-
2apps/settings/lib/AppInfo/Application.php
-
48apps/settings/lib/SetupChecks/SchedulingTableSize.php
-
6core/Application.php
-
2lib/private/Repair.php
@ -0,0 +1,35 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
/** |
|||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
|||
* SPDX-License-Identifier: AGPL-3.0-or-later |
|||
*/ |
|||
namespace OCA\DAV\BackgroundJob; |
|||
|
|||
use OCA\DAV\CalDAV\CalDavBackend; |
|||
use OCP\AppFramework\Utility\ITimeFactory; |
|||
use OCP\BackgroundJob\TimedJob; |
|||
use Psr\Log\LoggerInterface; |
|||
|
|||
class DeleteOutdatedSchedulingObjects extends TimedJob { |
|||
public function __construct( |
|||
private CalDavBackend $calDavBackend, |
|||
private LoggerInterface $logger, |
|||
ITimeFactory $timeFactory, |
|||
) { |
|||
parent::__construct($timeFactory); |
|||
$this->setInterval(23 * 60 * 60); |
|||
$this->setTimeSensitivity(self::TIME_INSENSITIVE); |
|||
} |
|||
|
|||
/** |
|||
* @param array $argument |
|||
*/ |
|||
protected function run($argument): void { |
|||
$time = $this->time->getTime() - (60 * 60); |
|||
$this->calDavBackend->deleteOutdatedSchedulingObjects($time, 50000); |
|||
$this->logger->info("Removed outdated scheduling objects"); |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
/** |
|||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
|||
* SPDX-License-Identifier: AGPL-3.0-or-later |
|||
*/ |
|||
namespace OCA\DAV\Migration; |
|||
|
|||
use OCA\DAV\BackgroundJob\DeleteOutdatedSchedulingObjects; |
|||
use OCA\DAV\CalDAV\CalDavBackend; |
|||
use OCP\AppFramework\Utility\ITimeFactory; |
|||
use OCP\BackgroundJob\IJobList; |
|||
use OCP\Migration\IOutput; |
|||
use OCP\Migration\IRepairStep; |
|||
|
|||
class DeleteSchedulingObjects implements IRepairStep { |
|||
public function __construct(private IJobList $jobList, |
|||
private ITimeFactory $time, |
|||
private CalDavBackend $calDavBackend |
|||
) { |
|||
} |
|||
|
|||
public function getName(): string { |
|||
return 'Handle outdated scheduling events'; |
|||
} |
|||
|
|||
public function run(IOutput $output): void { |
|||
$output->info('Cleaning up old scheduling events'); |
|||
$time = $this->time->getTime() - (60 * 60); |
|||
$this->calDavBackend->deleteOutdatedSchedulingObjects($time, 50000); |
|||
if (!$this->jobList->has(DeleteOutdatedSchedulingObjects::class, null)) { |
|||
$output->info('Adding background job to delete old scheduling objects'); |
|||
$this->jobList->add(DeleteOutdatedSchedulingObjects::class, null); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
/** |
|||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
|||
* SPDX-License-Identifier: AGPL-3.0-or-later |
|||
*/ |
|||
namespace OCA\Settings\SetupChecks; |
|||
|
|||
use OCP\IDBConnection; |
|||
use OCP\IL10N; |
|||
use OCP\SetupCheck\ISetupCheck; |
|||
use OCP\SetupCheck\SetupResult; |
|||
|
|||
class SchedulingTableSize implements ISetupCheck { |
|||
public function __construct( |
|||
private IL10N $l10n, |
|||
private IDBConnection $connection, |
|||
) { |
|||
} |
|||
|
|||
public function getName(): string { |
|||
return $this->l10n->t('Scheduling objects table size'); |
|||
} |
|||
|
|||
public function getCategory(): string { |
|||
return 'database'; |
|||
} |
|||
|
|||
public function run(): SetupResult { |
|||
$qb = $this->connection->getQueryBuilder(); |
|||
$qb->select($qb->func()->count('id')) |
|||
->from('schedulingobjects'); |
|||
$query = $qb->executeQuery(); |
|||
$count = $query->fetchOne(); |
|||
$query->closeCursor(); |
|||
|
|||
if ($count > 500000) { |
|||
return SetupResult::warning( |
|||
$this->l10n->t('You have more than 500 000 rows in the scheduling objects table. Please run the expensive repair jobs via occ maintenance:repair --include-expensive') |
|||
); |
|||
} |
|||
return SetupResult::success( |
|||
$this->l10n->t('Scheduling objects table size is within acceptable range.') |
|||
); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue