summaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Command
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-07-07 12:36:59 +0200
committerJulius Härtl <jus@bitgrid.net>2020-07-07 12:36:59 +0200
commit479aa975d38f3d7cb274b28ccaa322fc316bbb57 (patch)
tree7b7108f9597ac24edb52ca16032a7c79d813cba9 /apps/files/lib/Command
parent09b9f94c38dda015412cebf2cc8f7c7100001a67 (diff)
downloadnextcloud-server-479aa975d38f3d7cb274b28ccaa322fc316bbb57.tar.gz
nextcloud-server-479aa975d38f3d7cb274b28ccaa322fc316bbb57.zip
Add removal of mounts without storages to files:cleanup command
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/files/lib/Command')
-rw-r--r--apps/files/lib/Command/DeleteOrphanedFiles.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/apps/files/lib/Command/DeleteOrphanedFiles.php b/apps/files/lib/Command/DeleteOrphanedFiles.php
index c8ce9729ef7..9795448ff97 100644
--- a/apps/files/lib/Command/DeleteOrphanedFiles.php
+++ b/apps/files/lib/Command/DeleteOrphanedFiles.php
@@ -78,6 +78,39 @@ class DeleteOrphanedFiles extends Command {
}
$output->writeln("$deletedEntries orphaned file cache entries deleted");
+
+ $deletedMounts = $this->cleanupOrphanedMounts();
+ $output->writeln("$deletedMounts orphaned mount entries deleted");
return 0;
}
+
+ private function cleanupOrphanedMounts() {
+ $deletedEntries = 0;
+
+ $query = $this->connection->getQueryBuilder();
+ $query->select('m.storage_id')
+ ->from('mounts', 'm')
+ ->where($query->expr()->isNull('s.numeric_id'))
+ ->leftJoin('m', 'storages', 's', $query->expr()->eq('m.storage_id', 's.numeric_id'))
+ ->groupBy('storage_id')
+ ->setMaxResults(self::CHUNK_SIZE);
+
+ $deleteQuery = $this->connection->getQueryBuilder();
+ $deleteQuery->delete('mounts')
+ ->where($deleteQuery->expr()->eq('storage_id', $deleteQuery->createParameter('storageid')));
+
+ $deletedInLastChunk = self::CHUNK_SIZE;
+ while ($deletedInLastChunk === self::CHUNK_SIZE) {
+ $deletedInLastChunk = 0;
+ $result = $query->execute();
+ while ($row = $result->fetch()) {
+ $deletedInLastChunk++;
+ $deletedEntries += $deleteQuery->setParameter('storageid', (int) $row['storage_id'])
+ ->execute();
+ }
+ $result->closeCursor();
+ }
+
+ return $deletedEntries;
+ }
}