-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(caldav): automatically delete outdated scheduling objects
Signed-off-by: Anna Larch <anna@nextcloud.com>
- Loading branch information
1 parent
ddb840c
commit 6ba43b3
Showing
12 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
apps/dav/lib/BackgroundJob/DeleteOutdatedSchedulingObjects.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2024 Anna Larch <anna.larch@gmx.net> | ||
* | ||
* @author 2024 Anna Larch <anna.larch@gmx.net> | ||
* | ||
* @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 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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2024 Anna Larch <anna.larch@gmx.net> | ||
* | ||
* @author 2024 Anna Larch <anna.larch@gmx.net> | ||
* | ||
* @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 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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2024 Anna Larch <anna.larch@gmx.net> | ||
* | ||
* @author 2024 Anna Larch <anna.larch@gmx.net> | ||
* | ||
* @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 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.') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters