Skip to content

Commit 75e1641

Browse files
committed
Clustering: Cap clustering batch size at 10k
Signed-off-by: Marcel Klehr <[email protected]>
1 parent c4ba824 commit 75e1641

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/BackgroundJobs/ClusterFacesJob.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ClusterFacesJob extends QueuedJob {
1919
private IJobList $jobList;
2020
private LoggerInterface $logger;
2121

22+
public const BATCH_SIZE = 10000;
2223
public function __construct(ITimeFactory $time, Logger $logger, IJobList $jobList, FaceClusterAnalyzer $clusterAnalyzer) {
2324
parent::__construct($time);
2425
$this->logger = $logger;
@@ -35,7 +36,7 @@ protected function run($argument) {
3536
/** @var string $userId */
3637
$userId = $argument['userId'];
3738
try {
38-
$this->clusterAnalyzer->calculateClusters($userId);
39+
$this->clusterAnalyzer->calculateClusters($userId, self::BATCH_SIZE);
3940
} catch (\JsonException|Exception $e) {
4041
$this->logger->error('Failed to calculate face clusters', ['exception' => $e]);
4142
}

lib/Service/FaceClusterAnalyzer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(FaceDetectionMapper $faceDetections, FaceClusterMapp
3636
* @throws \OCP\DB\Exception
3737
* @throws \JsonException
3838
*/
39-
public function calculateClusters(string $userId): void {
39+
public function calculateClusters(string $userId, int $batchSize = -1): void {
4040
$this->logger->debug('ClusterDebug: Retrieving face detections for user ' . $userId);
4141

4242
$unclusteredDetections = $this->faceDetections->findUnclusteredByUserId($userId);
@@ -50,6 +50,10 @@ public function calculateClusters(string $userId): void {
5050
return;
5151
}
5252

53+
if ($batchSize > 0 && count($unclusteredDetections) > $batchSize) {
54+
$unclusteredDetections = array_slice($unclusteredDetections, 0, $batchSize);
55+
}
56+
5357
$this->logger->debug('ClusterDebug: Found ' . count($unclusteredDetections) . " unclustered detections. Calculating clusters.");
5458

5559
$sampledDetections = [];

0 commit comments

Comments
 (0)