Kate
7 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with
64 additions and
5 deletions
-
config/config.sample.php
-
core/BackgroundJobs/ExpirePreviewsJob.php
-
lib/composer/composer/autoload_classmap.php
-
lib/composer/composer/autoload_static.php
-
lib/private/Preview/Db/PreviewMapper.php
-
lib/private/Preview/PreviewService.php
-
lib/private/Setup.php
|
|
@ -2775,4 +2775,12 @@ $CONFIG = [ |
|
|
|
* Defaults to ``true`` |
|
|
|
*/ |
|
|
|
'enable_lazy_objects' => true, |
|
|
|
|
|
|
|
/** |
|
|
|
* Delete previews older than a certain number of days to reduce storage usage. |
|
|
|
* Less than one day is not allowed, so set it to 0 to disable the deletion. |
|
|
|
* |
|
|
|
* Defaults to ``0``. |
|
|
|
*/ |
|
|
|
'preview_expiration_days' => 0, |
|
|
|
]; |
|
|
@ -0,0 +1,38 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
declare(strict_types=1); |
|
|
|
|
|
|
|
/* |
|
|
|
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later |
|
|
|
*/ |
|
|
|
|
|
|
|
namespace OC\Core\BackgroundJobs; |
|
|
|
|
|
|
|
use OC\Preview\PreviewService; |
|
|
|
use OCP\AppFramework\Utility\ITimeFactory; |
|
|
|
use OCP\BackgroundJob\IJob; |
|
|
|
use OCP\BackgroundJob\TimedJob; |
|
|
|
use OCP\IConfig; |
|
|
|
|
|
|
|
class ExpirePreviewsJob extends TimedJob { |
|
|
|
public function __construct( |
|
|
|
ITimeFactory $time, |
|
|
|
private readonly IConfig $config, |
|
|
|
private readonly PreviewService $service, |
|
|
|
) { |
|
|
|
parent::__construct($time); |
|
|
|
|
|
|
|
$this->setTimeSensitivity(IJob::TIME_INSENSITIVE); |
|
|
|
$this->setInterval(60 * 60 * 24); |
|
|
|
} |
|
|
|
|
|
|
|
protected function run($argument): void { |
|
|
|
$days = $this->config->getSystemValueInt('preview_expiration_days'); |
|
|
|
if ($days <= 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
$this->service->deleteExpiredPreviews($days); |
|
|
|
} |
|
|
|
} |
|
|
@ -1248,6 +1248,7 @@ return array( |
|
|
|
'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => $baseDir . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\CheckForUserCertificates' => $baseDir . '/core/BackgroundJobs/CheckForUserCertificates.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\CleanupLoginFlowV2' => $baseDir . '/core/BackgroundJobs/CleanupLoginFlowV2.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\ExpirePreviewsJob' => $baseDir . '/core/BackgroundJobs/ExpirePreviewsJob.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\GenerateMetadataJob' => $baseDir . '/core/BackgroundJobs/GenerateMetadataJob.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\LookupServerSendCheckBackgroundJob' => $baseDir . '/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\MovePreviewJob' => $baseDir . '/core/BackgroundJobs/MovePreviewJob.php', |
|
|
|
|
|
@ -1289,6 +1289,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 |
|
|
|
'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\CheckForUserCertificates' => __DIR__ . '/../../..' . '/core/BackgroundJobs/CheckForUserCertificates.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\CleanupLoginFlowV2' => __DIR__ . '/../../..' . '/core/BackgroundJobs/CleanupLoginFlowV2.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\ExpirePreviewsJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/ExpirePreviewsJob.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\GenerateMetadataJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/GenerateMetadataJob.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\LookupServerSendCheckBackgroundJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/LookupServerSendCheckBackgroundJob.php', |
|
|
|
'OC\\Core\\BackgroundJobs\\MovePreviewJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/MovePreviewJob.php', |
|
|
|
|
|
@ -9,6 +9,8 @@ declare(strict_types=1); |
|
|
|
|
|
|
|
namespace OC\Preview\Db; |
|
|
|
|
|
|
|
use DateInterval; |
|
|
|
use DateTimeImmutable; |
|
|
|
use OCP\AppFramework\Db\Entity; |
|
|
|
use OCP\AppFramework\Db\QBMapper; |
|
|
|
use OCP\DB\Exception; |
|
|
@ -168,11 +170,6 @@ class PreviewMapper extends QBMapper { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function deleteAll(): void { |
|
|
|
$delete = $this->db->getQueryBuilder(); |
|
|
|
$delete->delete($this->getTableName()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @return \Generator<Preview> |
|
|
|
*/ |
|
|
@ -199,4 +196,12 @@ class PreviewMapper extends QBMapper { |
|
|
|
)); |
|
|
|
return $this->yieldEntities($qb); |
|
|
|
} |
|
|
|
|
|
|
|
public function deleteExpiredPreviews(int $maxDays): void { |
|
|
|
$delete = $this->db->getQueryBuilder(); |
|
|
|
$delete |
|
|
|
->delete($this->getTableName()) |
|
|
|
->where($delete->expr()->lt('mtime', $delete->createNamedParameter((new DateTimeImmutable())->sub(new DateInterval('P' . $maxDays . 'D'))->getTimestamp(), IQueryBuilder::PARAM_INT))) |
|
|
|
->executeStatement(); |
|
|
|
} |
|
|
|
} |
|
|
@ -106,4 +106,8 @@ class PreviewService { |
|
|
|
public function getAvailablePreviews(array $fileIds): array { |
|
|
|
return $this->previewMapper->getAvailablePreviews($fileIds); |
|
|
|
} |
|
|
|
|
|
|
|
public function deleteExpiredPreviews(int $maxDays): void { |
|
|
|
$this->previewMapper->deleteExpiredPreviews($maxDays); |
|
|
|
} |
|
|
|
} |
|
|
@ -14,6 +14,7 @@ use Exception; |
|
|
|
use InvalidArgumentException; |
|
|
|
use OC\Authentication\Token\PublicKeyTokenProvider; |
|
|
|
use OC\Authentication\Token\TokenCleanupJob; |
|
|
|
use OC\Core\BackgroundJobs\ExpirePreviewsJob; |
|
|
|
use OC\Core\BackgroundJobs\GenerateMetadataJob; |
|
|
|
use OC\Core\BackgroundJobs\MovePreviewJob; |
|
|
|
use OC\Log\Rotate; |
|
|
@ -507,6 +508,7 @@ class Setup { |
|
|
|
$jobList->add(CleanupDeletedUsers::class); |
|
|
|
$jobList->add(GenerateMetadataJob::class); |
|
|
|
$jobList->add(MovePreviewJob::class); |
|
|
|
$jobList->add(ExpirePreviewsJob::class); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|