Repository navigation
fix: honour classify --retry, avoid repeated dependency downloads, add duplicate face command and UI model download #1616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SchBenedikt
wants to merge
6
commits into
nextcloud:main
Choose a base branch
from
SchBenedikt:feat/issue-batch-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d9fa08
fix(Classify): skip already processed files with --retry
d3f1105
fix(InstallDeps): do not re-download installed TF.js and ffmpeg binaries
9a9ccd0
feat(Command): add recognize:remove-duplicate-faces with --dry-run
6c016dd
feat(Admin): download models from the admin settings
a1c9c08
fix: address review feedback on classify retry, install isolation and…
c1a73c8
fix: satisfy psalm on JobRun iteration and tag map keys
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * Copyright (c) 2026 The Recognize contributors. | ||
| * This file is licensed under the Affero General Public License version 3 or later. See the COPYING file. | ||
| */ | ||
|
|
||
| namespace OCA\Recognize\BackgroundJobs; | ||
|
|
||
| use OCA\Recognize\Service\DownloadModelsService; | ||
| use OCP\AppFramework\Utility\ITimeFactory; | ||
| use OCP\BackgroundJob\QueuedJob; | ||
| use Psr\Log\LoggerInterface; | ||
|
|
||
| /** | ||
| * Downloads the machine learning models in the background so that administrators | ||
| * can trigger the download from the admin settings without shell access. | ||
| */ | ||
| final class DownloadModelsJob extends QueuedJob { | ||
| public function __construct( | ||
| ITimeFactory $time, | ||
| private DownloadModelsService $downloader, | ||
| private LoggerInterface $logger, | ||
| ) { | ||
| parent::__construct($time); | ||
| } | ||
|
|
||
| /** | ||
| * @param mixed $argument unused, the job takes no arguments | ||
| */ | ||
| protected function run($argument): void { | ||
| try { | ||
| $this->downloader->download(); | ||
| } catch (\Throwable $e) { | ||
| // Keep the job from failing cron; the admin settings show that the models are still missing | ||
| $this->logger->error('Failed to download the machine learning models', ['exception' => $e]); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * Copyright (c) 2026 The Recognize contributors. | ||
| * This file is licensed under the Affero General Public License version 3 or later. See the COPYING file. | ||
| */ | ||
|
|
||
| namespace OCA\Recognize\Command; | ||
|
|
||
| use OCA\Recognize\Migration\RemoveDuplicateFaceDetections; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| /** | ||
| * Exposes the duplicate face detection repair step as a manually runnable command. | ||
| */ | ||
| final class RemoveDuplicateFaces extends Command { | ||
| public function __construct( | ||
| private RemoveDuplicateFaceDetections $repairStep, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| protected function configure(): void { | ||
| $this->setName('recognize:remove-duplicate-faces') | ||
| ->setDescription('Remove face detections that describe the same face of the same user in the same file more than once') | ||
| ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Only report the number of duplicate detections instead of removing them'); | ||
| } | ||
|
|
||
| protected function execute(InputInterface $input, OutputInterface $output): int { | ||
| $dryRun = (bool) $input->getOption('dry-run'); | ||
|
|
||
| try { | ||
| $count = $this->repairStep->removeDuplicates($dryRun); | ||
| } catch (\Throwable $e) { | ||
| $output->writeln('<error>Failed to remove duplicate face detections</error>'); | ||
| $output->writeln($e->getMessage()); | ||
| return 1; | ||
| } | ||
|
|
||
| if ($count === 0) { | ||
| $output->writeln('No duplicate face detections found.'); | ||
| } elseif ($dryRun) { | ||
| $output->writeln('Would remove ' . $count . ' duplicate face detections. Run without --dry-run to remove them.'); | ||
| } else { | ||
| $output->writeln('Removed ' . $count . ' duplicate face detections.'); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're claiming "getTagsForFiles() keys its result by the string file id, but the lookup used the int $lastFileId, so the array access was always undefined", but PHP turns numeric string keys into ints, so IMO the old lookup worked. Did you try it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right — I verified it: PHP casts numeric string keys to int, so
$tagsByFile[$lastFileId]did resolve, and the object comparison inin_array()was non-strict so it worked too. The PR description claimed otherwise and I've corrected it. What was actually wrong with the previous revision was semantic, not the lookup: it skipped tagged files for every classifier including faces (see the other thread), and it still cost ~2 queries per file. Both are fixed in a1c9c08.