diff options
author | Robin Appelman <robin@icewind.nl> | 2025-04-07 18:12:42 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2025-04-07 19:35:41 +0200 |
commit | c89e3c2f74d6f0bf253dddc18a4a4d305821cbe7 (patch) | |
tree | 77ae38024de782c713f8e0f9ff2a45f64f75b9d5 /lib/private | |
parent | 084487bdd5ac052fc831509780ce2ffe5517eb41 (diff) | |
download | nextcloud-server-files-cache-node.tar.gz nextcloud-server-files-cache-node.zip |
feat: move file cache to a background jobfiles-cache-node
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Cache/File.php | 12 | ||||
-rw-r--r-- | lib/private/Repair/NC32/AddFileCacheGcBackgroundJob.php | 29 |
2 files changed, 36 insertions, 5 deletions
diff --git a/lib/private/Cache/File.php b/lib/private/Cache/File.php index 99b14e92787..e8c436636ab 100644 --- a/lib/private/Cache/File.php +++ b/lib/private/Cache/File.php @@ -28,12 +28,14 @@ class File implements ICache { * @throws \OC\ForbiddenException * @throws \OC\User\NoUserException */ - protected function getStorage() { + protected function getStorage(?IUser $user = null): Folder { if ($this->storage !== null) { return $this->storage; } - $session = Server::get(IUserSession::class); - $user = $session->getUser(); + if (!$user) { + $session = Server::get(IUserSession::class); + $user = $session->getUser(); + } $rootFolder = Server::get(IRootFolder::class); if ($user) { $userId = $user->getUID(); @@ -156,8 +158,8 @@ class File implements ICache { * Runs GC * @throws \OC\ForbiddenException */ - public function gc() { - $storage = $this->getStorage(); + public function gc(?IUser $user = null) { + $storage = $this->getStorage($user); // extra hour safety, in case of stray part chunks that take longer to write, // because touch() is only called after the chunk was finished diff --git a/lib/private/Repair/NC32/AddFileCacheGcBackgroundJob.php b/lib/private/Repair/NC32/AddFileCacheGcBackgroundJob.php new file mode 100644 index 00000000000..b6b0af1bf32 --- /dev/null +++ b/lib/private/Repair/NC32/AddFileCacheGcBackgroundJob.php @@ -0,0 +1,29 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OC\Repair\NC32; + +use OC\Core\BackgroundJobs\FileCacheGcJob; +use OCP\BackgroundJob\IJobList; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class AddFileCacheGcBackgroundJob implements IRepairStep { + public function __construct( + private readonly IJobList $jobList, + ) { + } + + public function getName(): string { + return 'Add background job to cleanup file cache'; + } + + public function run(IOutput $output) { + $this->jobList->add(FileCacheGcJob::class); + } +} |