aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/BackgroundJob
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2022-10-02 12:07:51 +0200
committerSimon L. (Rebase PR Action) <szaimen@e.mail.de>2022-10-27 20:12:13 +0000
commit6f158733211749ca6d70858ee58ba35e85d46e81 (patch)
tree2648886b9c00d5278bee9514fbc7cb533e866303 /apps/dav/lib/BackgroundJob
parentd007088cf5d89e29065991e0cbe2c890dfa13d96 (diff)
downloadnextcloud-server-6f158733211749ca6d70858ee58ba35e85d46e81.tar.gz
nextcloud-server-6f158733211749ca6d70858ee58ba35e85d46e81.zip
Add a background job to prune outdated sync tokens
We remove all outdated sync tokens, based on their auto-incremented ID. By default we only keep the last 10 000, but this can be configurable. Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/dav/lib/BackgroundJob')
-rw-r--r--apps/dav/lib/BackgroundJob/PruneOutdatedSyncTokensJob.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/apps/dav/lib/BackgroundJob/PruneOutdatedSyncTokensJob.php b/apps/dav/lib/BackgroundJob/PruneOutdatedSyncTokensJob.php
new file mode 100644
index 00000000000..deca55a26cb
--- /dev/null
+++ b/apps/dav/lib/BackgroundJob/PruneOutdatedSyncTokensJob.php
@@ -0,0 +1,64 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2022 Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
+ * @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 OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\TimedJob;
+use OCA\DAV\AppInfo\Application;
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\CardDAV\CardDavBackend;
+use OCP\IConfig;
+use Psr\Log\LoggerInterface;
+
+class PruneOutdatedSyncTokensJob extends TimedJob {
+
+ private IConfig $config;
+ private LoggerInterface $logger;
+ private CardDavBackend $cardDavBackend;
+ private CalDavBackend $calDavBackend;
+
+ public function __construct(ITimeFactory $timeFactory, CalDavBackend $calDavBackend, CardDavBackend $cardDavBackend, IConfig $config, LoggerInterface $logger) {
+ parent::__construct($timeFactory);
+ $this->calDavBackend = $calDavBackend;
+ $this->cardDavBackend = $cardDavBackend;
+ $this->config = $config;
+ $this->logger = $logger;
+ $this->setInterval(60 * 60 * 24); // One day
+ $this->setTimeSensitivity(self::TIME_INSENSITIVE);
+ }
+
+ public function run($argument) {
+ $limit = max(1, (int) $this->config->getAppValue(Application::APP_ID, 'totalNumberOfSyncTokensToKeep', '10000'));
+
+ $prunedCalendarSyncTokens = $this->calDavBackend->pruneOutdatedSyncTokens($limit);
+ $prunedAddressBookSyncTokens = $this->cardDavBackend->pruneOutdatedSyncTokens($limit);
+
+ $this->logger->info('Pruned {calendarSyncTokensNumber} calendar sync tokens and {addressBooksSyncTokensNumber} address book sync tokens', [
+ 'calendarSyncTokensNumber' => $prunedCalendarSyncTokens,
+ 'addressBooksSyncTokensNumber' => $prunedAddressBookSyncTokens
+ ]);
+ }
+}