diff options
author | provokateurin <kate@provokateurin.de> | 2025-05-20 13:00:16 +0200 |
---|---|---|
committer | provokateurin <kate@provokateurin.de> | 2025-05-20 13:00:16 +0200 |
commit | b991c0e21c4b96a7758950ba991dfbecb9471af9 (patch) | |
tree | ae889da66d682611ae9caa951d65aea00596d866 /lib | |
parent | 565d524cd4b95e24469f9d0c105cd72dddbdd757 (diff) | |
download | nextcloud-server-perf/files/cache-garbage-collection-background-job.tar.gz nextcloud-server-perf/files/cache-garbage-collection-background-job.zip |
perf(files): Move cache garbage collection to a background jobperf/files/cache-garbage-collection-background-job
Signed-off-by: provokateurin <kate@provokateurin.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 17 | ||||
-rw-r--r-- | lib/private/Cache/File.php | 18 |
2 files changed, 12 insertions, 23 deletions
diff --git a/lib/base.php b/lib/base.php index ad80df357c5..92306ab6296 100644 --- a/lib/base.php +++ b/lib/base.php @@ -889,23 +889,6 @@ class OC { $throttler = Server::get(IThrottler::class); $throttler->resetDelay($request->getRemoteAddress(), 'login', ['user' => $uid]); } - - try { - $cache = new \OC\Cache\File(); - $cache->gc(); - } catch (\OC\ServerNotAvailableException $e) { - // not a GC exception, pass it on - throw $e; - } catch (\OC\ForbiddenException $e) { - // filesystem blocked for this request, ignore - } catch (\Exception $e) { - // a GC exception should not prevent users from using OC, - // so log the exception - Server::get(LoggerInterface::class)->warning('Exception when running cache gc.', [ - 'app' => 'core', - 'exception' => $e, - ]); - } }); } } diff --git a/lib/private/Cache/File.php b/lib/private/Cache/File.php index ceddf472ebd..91c19d437e3 100644 --- a/lib/private/Cache/File.php +++ b/lib/private/Cache/File.php @@ -26,14 +26,20 @@ class File implements ICache { * @throws \OC\ForbiddenException * @throws \OC\User\NoUserException */ - protected function getStorage() { + protected function getStorage(?string $userId = null) { if ($this->storage !== null) { return $this->storage; } - $session = Server::get(IUserSession::class); - if ($session->isLoggedIn()) { + + if ($userId === null) { + $session = Server::get(IUserSession::class); + if ($session->isLoggedIn()) { + $userId = $session->getUser()->getUID(); + } + } + + if ($userId !== null) { $rootView = new View(); - $userId = $session->getUser()->getUID(); Filesystem::initMountPoints($userId); if (!$rootView->file_exists('/' . $userId . '/cache')) { $rootView->mkdir('/' . $userId . '/cache'); @@ -154,8 +160,8 @@ class File implements ICache { * Runs GC * @throws \OC\ForbiddenException */ - public function gc() { - $storage = $this->getStorage(); + public function gc(?string $userId = null) { + $storage = $this->getStorage($userId); if ($storage) { // extra hour safety, in case of stray part chunks that take longer to write, // because touch() is only called after the chunk was finished |