From c89e3c2f74d6f0bf253dddc18a4a4d305821cbe7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 7 Apr 2025 18:12:42 +0200 Subject: feat: move file cache to a background job Signed-off-by: Robin Appelman --- core/BackgroundJobs/FileCacheGcJob.php | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 core/BackgroundJobs/FileCacheGcJob.php (limited to 'core/BackgroundJobs/FileCacheGcJob.php') diff --git a/core/BackgroundJobs/FileCacheGcJob.php b/core/BackgroundJobs/FileCacheGcJob.php new file mode 100644 index 00000000000..e0c8a1d7881 --- /dev/null +++ b/core/BackgroundJobs/FileCacheGcJob.php @@ -0,0 +1,58 @@ +setTimeSensitivity(self::TIME_INSENSITIVE); + $this->setInterval(24 * 60 * 60); + } + + protected function run(mixed $argument): void { + $offset = $this->appConfig->getValueInt('core', 'files_gc_offset'); + + $users = $this->userManager->getSeenUsers($offset); + $start = time(); + $count = 0; + foreach ($users as $user) { + $cache = new File(); + try { + $cache->gc($user); + } catch (\Exception $e) { + $this->logger->warning('Exception when running cache gc.', [ + 'app' => 'core', + 'exception' => $e, + ]); + } + $count++; + $now = time(); + + // almost time for the next job run, stop early and save our location + if ($now - $start > 23 * 60 * 60) { + $this->appConfig->setValueInt('core', 'files_gc_offset', $offset + $count); + return; + } + } + $this->appConfig->setValueInt('core', 'files_gc_offset', 0); + } +} -- cgit v1.2.3