Skip to content

Commit

Permalink
Allow removing files in excluded paths with occ music:scan --remove-o…
Browse files Browse the repository at this point in the history
…bsolete

The option `--remove-obsolete` on the command `occ music:scan` now removes
also any tracks which now reside in an excluded folder. This is in addition
to its former function of removing such tracks which are no longer accessible
by the user at all.

The new logic for the `--remove-obsolete` switch is also a lot more efficient
on huge libraries. As an example, checking for the obsolete files now took
~40 seconds on library of more than 60k tracks. With the old implementation,
I got tired of waiting and terminated the test after 10 minutes, so it was at
least 15 times slower and maybe much more.

refs #762
  • Loading branch information
paulijar committed Oct 3, 2020
1 parent d684fdc commit cd524a3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion command/scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function scanUser($user, OutputInterface $output, $rescan, $cleanObsol
$output->writeln("Checking availability of previously scanned files of <info>$user</info>...");
$removedCount = $this->scanner->removeUnavailableFiles($user, $userHome);
if ($removedCount > 0) {
$output->writeln("Removed $removedCount tracks which are no longer accessible by $user");
$output->writeln("Removed $removedCount tracks which are no longer within the library of <info>$user</info>");
}
}

Expand Down
12 changes: 4 additions & 8 deletions utility/scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,17 +516,13 @@ public function scanFiles($userId, $userHome, $fileIds, OutputInterface $debugOu
*/
public function removeUnavailableFiles($userId, $userHome) {
$indexedFiles = $this->getScannedFileIds($userId);
$unavailableFiles = [];
foreach ($indexedFiles as $fileId) {
$fileNodes = $userHome->getById($fileId);
if (empty($fileNodes)) {
$this->logger->log("File $fileId is not available for user $userId, removing", 'info');
$unavailableFiles[] = $fileId;
}
}
$availableFiles = $this->getAllMusicFileIds($userId);
$unavailableFiles = Util::arrayDiff($indexedFiles, $availableFiles);

$count = \count($unavailableFiles);
if ($count > 0) {
$this->logger->log('The following files are no longer available within the library of the '.
"user $userId, removing: " . \print_r($unavailableFiles, true), 'info');
$this->deleteAudio($unavailableFiles, [$userId]);
}
return $count;
Expand Down

0 comments on commit cd524a3

Please sign in to comment.