Skip to content

Commit defb6e8

Browse files
CarlSchwanbackportbot[bot]
authored andcommitted
perf(trashbin): Batch propagate file deletions
Assisted-by: ClaudeCode:claude-opus-4-8 Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent e1094a7 commit defb6e8

1 file changed

Lines changed: 42 additions & 20 deletions

File tree

apps/files_trashbin/lib/Trashbin.php

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use OCP\EventDispatcher\IEventDispatcher;
3131
use OCP\EventDispatcher\IEventListener;
3232
use OCP\Exceptions\AbortedEventException;
33+
use OCP\Files\Cache\IPropagator;
3334
use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
3435
use OCP\Files\File;
3536
use OCP\Files\Folder;
@@ -939,21 +940,27 @@ protected static function deleteFiles(array $files, string $user, int|float $ava
939940
$size = 0;
940941

941942
if ($availableSpace <= 0) {
942-
foreach ($files as $file) {
943-
if ($availableSpace <= 0 && $expiration->isExpired($file['mtime'], true)) {
944-
$tmp = self::delete($file['name'], $user, $file['mtime']);
945-
Server::get(LoggerInterface::class)->info(
946-
'remove "' . $file['name'] . '" (' . $tmp . 'B) to meet the limit of trash bin size (50% of available quota) for user "{user}"',
947-
[
948-
'app' => 'files_trashbin',
949-
'user' => $user,
950-
]
951-
);
952-
$availableSpace += $tmp;
953-
$size += $tmp;
954-
} else {
955-
break;
943+
$propagator = self::getUserStoragePropagator($user);
944+
$propagator?->beginBatch();
945+
try {
946+
foreach ($files as $file) {
947+
if ($availableSpace <= 0 && $expiration->isExpired($file['mtime'], true)) {
948+
$tmp = self::delete($file['name'], $user, $file['mtime']);
949+
Server::get(LoggerInterface::class)->info(
950+
'remove "' . $file['name'] . '" (' . $tmp . 'B) to meet the limit of trash bin size (50% of available quota) for user "{user}"',
951+
[
952+
'app' => 'files_trashbin',
953+
'user' => $user,
954+
]
955+
);
956+
$availableSpace += $tmp;
957+
$size += $tmp;
958+
} else {
959+
break;
960+
}
956961
}
962+
} finally {
963+
$propagator?->commitBatch();
957964
}
958965
}
959966
return $size;
@@ -970,10 +977,17 @@ public static function deleteExpiredFiles($files, $user) {
970977
$expiration = Server::get(Expiration::class);
971978
$size = 0;
972979
$count = 0;
973-
foreach ($files as $file) {
974-
$timestamp = $file['mtime'];
975-
$filename = $file['name'];
976-
if ($expiration->isExpired($timestamp)) {
980+
981+
$propagator = self::getUserStoragePropagator($user);
982+
$propagator?->beginBatch();
983+
try {
984+
foreach ($files as $file) {
985+
$timestamp = $file['mtime'];
986+
$filename = $file['name'];
987+
if (!$expiration->isExpired($timestamp)) {
988+
break;
989+
}
990+
977991
try {
978992
$size += self::delete($filename, $user, $timestamp);
979993
$count++;
@@ -993,14 +1007,22 @@ public static function deleteExpiredFiles($files, $user) {
9931007
'user' => $user,
9941008
],
9951009
);
996-
} else {
997-
break;
9981010
}
1011+
} finally {
1012+
$propagator?->commitBatch();
9991013
}
10001014

10011015
return [$size, $count];
10021016
}
10031017

1018+
private static function getUserStoragePropagator(string $user): ?IPropagator {
1019+
try {
1020+
return Server::get(IRootFolder::class)->getUserFolder($user)->getStorage()->getPropagator();
1021+
} catch (\Exception) {
1022+
return null;
1023+
}
1024+
}
1025+
10041026
/**
10051027
* recursive copy to copy a whole directory
10061028
*

0 commit comments

Comments
 (0)