diff --git a/mobile/lib/services/face_ml/face_ml_service.dart b/mobile/lib/services/face_ml/face_ml_service.dart index 0fedda70d..789430386 100644 --- a/mobile/lib/services/face_ml/face_ml_service.dart +++ b/mobile/lib/services/face_ml/face_ml_service.dart @@ -446,7 +446,7 @@ class FaceMlService { final List> chunks = sortedBylocalID.chunks(kParallelism); outerLoop: for (final chunk in chunks) { - final futures = []; + final futures = >[]; final List fileIds = []; // Try to find embeddings on the remote server for (final f in chunk) { @@ -495,8 +495,12 @@ class FaceMlService { } futures.add(processImage(enteFile)); } - await Future.wait(futures); - fileAnalyzedCount += futures.length; + final awaitedFutures = await Future.wait(futures); + final sumFutures = awaitedFutures.fold( + 0, + (previousValue, element) => previousValue + (element ? 1 : 0), + ); + fileAnalyzedCount += sumFutures; } stopwatch.stop(); @@ -514,7 +518,7 @@ class FaceMlService { } } - Future processImage(EnteFile enteFile) async { + Future processImage(EnteFile enteFile) async { _logger.info( "`indexAllImages()` on file number start processing image with uploadedFileID: ${enteFile.uploadedFileID}", ); @@ -526,10 +530,7 @@ class FaceMlService { // disposeImageIsolateAfterUse: false, ); if (result == null) { - _logger.warning( - "Image not analyzed with uploadedFileID: ${enteFile.uploadedFileID}", - ); - return; + return false; } final List faces = []; if (!result.hasFaces) { @@ -599,12 +600,14 @@ class FaceMlService { ), ); await FaceMLDataDB.instance.bulkInsertFaces(faces); + return true; } catch (e, s) { _logger.severe( "Failed to analyze using FaceML for image with ID: ${enteFile.uploadedFileID}", e, s, ); + return true; } } @@ -1153,6 +1156,9 @@ class FaceMlService { } bool _skipAnalysisEnteFile(EnteFile enteFile, Map indexedFileIds) { + if (isImageIndexRunning == false) { + return true; + } // Skip if the file is not uploaded or not owned by the user if (!enteFile.isUploaded || enteFile.isOwner == false) { return true;