From 4cc8be748c1f5bb363f746dd88e08d262c99f8d9 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Thu, 26 Sep 2024 12:02:19 +0530 Subject: [PATCH] Fix indexing into the wrong faces --- web/packages/new/photos/services/ml/cluster.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/web/packages/new/photos/services/ml/cluster.ts b/web/packages/new/photos/services/ml/cluster.ts index d9c69a2bb0..4d4fbe1026 100644 --- a/web/packages/new/photos/services/ml/cluster.ts +++ b/web/packages/new/photos/services/ml/cluster.ts @@ -263,11 +263,11 @@ interface ClusteringState { } const clusterBatchLinear = async ( - faces: ClusterFace[], + batch: ClusterFace[], state: ClusteringState, onProgress: (progress: ClusteringProgress) => void, ) => { - const [clustered, unclustered] = faces.reduce< + const [clusteredFaces, unclusteredFaces] = batch.reduce< [ClusterFace[], ClusterFace[]] >( (split, face) => ( @@ -277,21 +277,21 @@ const clusterBatchLinear = async ( [[], []], ); - if (!unclustered.length) { + if (!unclusteredFaces.length) { // Optimization: early exit if nothing in batch is unclustered. In a // single test (so it might be not be a universal benefit) of ~8k faces, // it helped reduce the no-op time by 10x. - onProgress({ completed: faces.length, total: faces.length }); + onProgress({ completed: batch.length, total: batch.length }); return; } // Sort the faces so that the already clustered ones are at the front. - const sortedFaces = clustered.concat(unclustered); + const faces = clusteredFaces.concat(unclusteredFaces); // For each face in the batch - for (const [i, fi] of sortedFaces.entries()) { + for (const [i, fi] of faces.entries()) { if (i % 100 == 0) { - onProgress({ completed: i, total: faces.length }); + onProgress({ completed: i, total: batch.length }); // See: [Note: Draining the event loop during clustering] await wait(0); }