-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(caldav): automatically delete outdated scheduling objects #45235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
35 changes: 35 additions & 0 deletions
35
apps/dav/lib/BackgroundJob/DeleteOutdatedSchedulingObjects.php
This file contains hidden or 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,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); | ||
miaulalala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->calDavBackend->deleteOutdatedSchedulingObjects($time, 50000); | ||
| $this->logger->info("Removed outdated scheduling objects"); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,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.') | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not 24? 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nickvergessen can explain 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would move back all the time, as the run time is not 0 seconds and it can be started with up to 14 minutes delay.
That would mean it would fall further back and back in the "maintenance time window" and eventually skip some day as current time + 24h is outside of maintenance window.
With 23h it will just be saver to run every day.