summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-04-15 21:07:09 +0200
committerGitHub <noreply@github.com>2024-04-15 21:07:09 +0200
commitb5e3508a0b191605839eed8a3260e2f60074b460 (patch)
tree26089a1e4c6d367e3886f83060033d5f111eb31e
parent10fc78a9ea0d8a2081c1185f8f4c4b63b631d88e (diff)
parent1d34f0a824e15ad5ed685d05dc46910362e99404 (diff)
downloadnextcloud-server-b5e3508a0b191605839eed8a3260e2f60074b460.tar.gz
nextcloud-server-b5e3508a0b191605839eed8a3260e2f60074b460.zip
Merge pull request #38933 from nextcloud/orphaned-entries-filecache-extended
feat: remove orphaned entries from filecache_extended
-rw-r--r--apps/files/lib/Command/DeleteOrphanedFiles.php38
-rw-r--r--apps/files/tests/Command/DeleteOrphanedFilesTest.php3
2 files changed, 39 insertions, 2 deletions
diff --git a/apps/files/lib/Command/DeleteOrphanedFiles.php b/apps/files/lib/Command/DeleteOrphanedFiles.php
index 4b7179271f5..1b5727ae546 100644
--- a/apps/files/lib/Command/DeleteOrphanedFiles.php
+++ b/apps/files/lib/Command/DeleteOrphanedFiles.php
@@ -24,9 +24,11 @@
*/
namespace OCA\Files\Command;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
@@ -44,7 +46,8 @@ class DeleteOrphanedFiles extends Command {
protected function configure(): void {
$this
->setName('files:cleanup')
- ->setDescription('cleanup filecache');
+ ->setDescription('cleanup filecache')
+ ->addOption('skip-filecache-extended', null, InputOption::VALUE_NONE, 'don\'t remove orphaned entries from filecache_extended');
}
public function execute(InputInterface $input, OutputInterface $output): int {
@@ -75,11 +78,44 @@ class DeleteOrphanedFiles extends Command {
$output->writeln("$deletedEntries orphaned file cache entries deleted");
+ if (!$input->getOption('skip-filecache-extended')) {
+ $deletedFileCacheExtended = $this->cleanupOrphanedFileCacheExtended();
+ $output->writeln("$deletedFileCacheExtended orphaned file cache extended entries deleted");
+ }
+
+
$deletedMounts = $this->cleanupOrphanedMounts();
$output->writeln("$deletedMounts orphaned mount entries deleted");
return self::SUCCESS;
}
+ private function cleanupOrphanedFileCacheExtended(): int {
+ $deletedEntries = 0;
+
+ $query = $this->connection->getQueryBuilder();
+ $query->select('fce.fileid')
+ ->from('filecache_extended', 'fce')
+ ->leftJoin('fce', 'filecache', 'fc', $query->expr()->eq('fce.fileid', 'fc.fileid'))
+ ->where($query->expr()->isNull('fc.fileid'))
+ ->setMaxResults(self::CHUNK_SIZE);
+
+ $deleteQuery = $this->connection->getQueryBuilder();
+ $deleteQuery->delete('filecache_extended')
+ ->where($deleteQuery->expr()->in('fileid', $deleteQuery->createParameter('idsToDelete')));
+
+ $result = $query->executeQuery();
+ while ($result->rowCount() > 0) {
+ $idsToDelete = $result->fetchAll(\PDO::FETCH_COLUMN);
+
+ $deleteQuery->setParameter('idsToDelete', $idsToDelete, IQueryBuilder::PARAM_INT_ARRAY);
+ $deletedEntries += $deleteQuery->executeStatement();
+
+ $result = $query->executeQuery();
+ }
+
+ return $deletedEntries;
+ }
+
private function cleanupOrphanedMounts(): int {
$deletedEntries = 0;
diff --git a/apps/files/tests/Command/DeleteOrphanedFilesTest.php b/apps/files/tests/Command/DeleteOrphanedFilesTest.php
index 520d3278e64..ee1144963ac 100644
--- a/apps/files/tests/Command/DeleteOrphanedFilesTest.php
+++ b/apps/files/tests/Command/DeleteOrphanedFilesTest.php
@@ -132,10 +132,11 @@ class DeleteOrphanedFilesTest extends TestCase {
// parent folder, `files`, ´test` and `welcome.txt` => 4 elements
$output
- ->expects($this->exactly(2))
+ ->expects($this->exactly(3))
->method('writeln')
->withConsecutive(
['3 orphaned file cache entries deleted'],
+ ['0 orphaned file cache extended entries deleted'],
['1 orphaned mount entries deleted'],
);