Skip to content

Commit df018cf

Browse files
committed
fix(gc): Implement cache_chunk_gc_ttl
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
1 parent ac3d09d commit df018cf

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

apps/dav/lib/BackgroundJob/UploadCleanup.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use OCP\Files\Folder;
1717
use OCP\Files\IRootFolder;
1818
use OCP\Files\NotFoundException;
19+
use OCP\IConfig;
20+
use OCP\Server;
1921
use Psr\Log\LoggerInterface;
2022

2123
class UploadCleanup extends TimedJob {
@@ -47,8 +49,9 @@ protected function run($argument) {
4749
return;
4850
}
4951

50-
// Remove if all files have an mtime of more than a day
51-
$time = $this->time->getTime() - 60 * 60 * 24;
52+
// Remove if all files have an mtime of more than a day or configured TTL
53+
$ttl = Server::get(IConfig::class)->getSystemValueInt('cache_chunk_gc_ttl', 60 * 60 * 24);
54+
$time = $this->time->getTime() - $ttl;
5255

5356
if (!($uploadFolder instanceof Folder)) {
5457
$this->logger->error('Found a file inside the uploads folder. Uid: ' . $uid . ' folder: ' . $folder);
@@ -61,8 +64,6 @@ protected function run($argument) {
6164

6265
/** @var File[] $files */
6366
$files = $uploadFolder->getDirectoryListing();
64-
65-
// The folder has to be more than a day old
6667
$initial = $uploadFolder->getMTime() < $time;
6768

6869
$expire = array_reduce($files, function (bool $carry, File $file) use ($time) {

lib/private/Cache/File.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ public function clear($prefix = '') {
157157
public function gc() {
158158
$storage = $this->getStorage();
159159
if ($storage) {
160-
// extra hour safety, in case of stray part chunks that take longer to write,
161-
// because touch() is only called after the chunk was finished
162-
$now = time() - 3600;
160+
$ttl = \OC::$server->getConfig()->getSystemValueInt('cache_chunk_gc_ttl', 60 * 60 * 24);
161+
$now = time() - $ttl;
162+
163163
$dh = $storage->opendir('/');
164164
if (!is_resource($dh)) {
165165
return null;

0 commit comments

Comments
 (0)