From db2d0bb7e9274aefb747b45e31317aa00dd95acd Mon Sep 17 00:00:00 2001 From: Prateek Sunal Date: Sun, 24 Aug 2025 02:04:09 +0530 Subject: [PATCH] fix: remove formatting from ml_service --- .../services/machine_learning/ml_service.dart | 87 ++++++++----------- 1 file changed, 38 insertions(+), 49 deletions(-) diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart index cb0c8d437c..45e42e2b0b 100644 --- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart +++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart @@ -131,8 +131,8 @@ class MLService { _isRunningML = true; await sync(); - final int unclusteredFacesCount = await mlDataDB - .getUnclusteredFaceCount(); + final int unclusteredFacesCount = + await mlDataDB.getUnclusteredFaceCount(); if (unclusteredFacesCount > _kForceClusteringFaceCount) { _logger.info( "There are $unclusteredFacesCount unclustered faces, doing clustering first", @@ -279,8 +279,8 @@ class MLService { try { // Get a sense of the total number of faces in the database final int totalFaces = await mlDataDB.getTotalFaceCount(); - final fileIDToCreationTime = await FilesDB.instance - .getFileIDToCreationTime(); + final fileIDToCreationTime = + await FilesDB.instance.getFileIDToCreationTime(); final startEmbeddingFetch = DateTime.now(); // read all embeddings final result = await mlDataDB.getFaceInfoForClustering( @@ -300,9 +300,8 @@ class MLService { } // sort the embeddings based on file creation time, newest first allFaceInfoForClustering.sort((b, a) { - return fileIDToCreationTime[a.fileID]!.compareTo( - fileIDToCreationTime[b.fileID]!, - ); + return fileIDToCreationTime[a.fileID]! + .compareTo(fileIDToCreationTime[b.fileID]!); }); _logger.info( 'Getting and sorting embeddings took ${DateTime.now().difference(startEmbeddingFetch).inMilliseconds} ms for ${allFaceInfoForClustering.length} embeddings' @@ -310,8 +309,8 @@ class MLService { ); // Get the current cluster statistics - final Map oldClusterSummaries = await mlDataDB - .getAllClusterSummary(); + final Map oldClusterSummaries = + await mlDataDB.getAllClusterSummary(); if (clusterInBuckets) { const int bucketSize = 10000; @@ -358,24 +357,22 @@ class MLService { } } - final clusteringResult = await FaceClusteringService.instance - .predictLinearIsolate( - faceInfoForClustering.toSet(), - fileIDToCreationTime: fileIDToCreationTime, - offset: offset, - oldClusterSummaries: oldClusterSummaries, - ); + final clusteringResult = + await FaceClusteringService.instance.predictLinearIsolate( + faceInfoForClustering.toSet(), + fileIDToCreationTime: fileIDToCreationTime, + offset: offset, + oldClusterSummaries: oldClusterSummaries, + ); if (clusteringResult == null) { _logger.warning("faceIdToCluster is null"); return; } - await mlDataDB.updateFaceIdToClusterId( - clusteringResult.newFaceIdToCluster, - ); - await mlDataDB.clusterSummaryUpdate( - clusteringResult.newClusterSummaries, - ); + await mlDataDB + .updateFaceIdToClusterId(clusteringResult.newFaceIdToCluster); + await mlDataDB + .clusterSummaryUpdate(clusteringResult.newClusterSummaries); Bus.instance.fire(PeopleChangedEvent()); for (final faceInfo in faceInfoForClustering) { faceInfo.clusterId ??= @@ -398,12 +395,12 @@ class MLService { } else { final clusterStartTime = DateTime.now(); // Cluster the embeddings using the linear clustering algorithm, returning a map from faceID to clusterID - final clusteringResult = await FaceClusteringService.instance - .predictLinearIsolate( - allFaceInfoForClustering.toSet(), - fileIDToCreationTime: fileIDToCreationTime, - oldClusterSummaries: oldClusterSummaries, - ); + final clusteringResult = + await FaceClusteringService.instance.predictLinearIsolate( + allFaceInfoForClustering.toSet(), + fileIDToCreationTime: fileIDToCreationTime, + oldClusterSummaries: oldClusterSummaries, + ); if (clusteringResult == null) { _logger.warning("faceIdToCluster is null"); return; @@ -417,22 +414,16 @@ class MLService { _logger.info( 'Updating ${clusteringResult.newFaceIdToCluster.length} FaceIDs with clusterIDs in the DB', ); - await mlDataDB.updateFaceIdToClusterId( - clusteringResult.newFaceIdToCluster, - ); - await mlDataDB.clusterSummaryUpdate( - clusteringResult.newClusterSummaries, - ); + await mlDataDB + .updateFaceIdToClusterId(clusteringResult.newFaceIdToCluster); + await mlDataDB + .clusterSummaryUpdate(clusteringResult.newClusterSummaries); Bus.instance.fire(PeopleChangedEvent()); - _logger.info( - 'Done updating FaceIDs with clusterIDs in the DB, in ' - '${DateTime.now().difference(clusterDoneTime).inSeconds} seconds', - ); + _logger.info('Done updating FaceIDs with clusterIDs in the DB, in ' + '${DateTime.now().difference(clusterDoneTime).inSeconds} seconds'); } - _logger.info( - 'clusterAllImages() finished, in ' - '${DateTime.now().difference(clusterAllImagesTime).inSeconds} seconds', - ); + _logger.info('clusterAllImages() finished, in ' + '${DateTime.now().difference(clusterAllImagesTime).inSeconds} seconds'); } catch (e, s) { _logger.severe("`clusterAllImages` failed", e, s); } finally { @@ -465,8 +456,7 @@ class MLService { actuallyRanML = result.ranML; if (!actuallyRanML) return actuallyRanML; // Prepare storing data on remote - final FileDataEntity dataEntity = - instruction.existingRemoteFileML ?? + final FileDataEntity dataEntity = instruction.existingRemoteFileML ?? FileDataEntity.empty( instruction.file.uploadedFileID!, DataType.mlData, @@ -529,9 +519,9 @@ class MLService { final fileType = instruction.file.fileType; final bool acceptedIssue = errorString.contains('ThumbnailRetrievalException') || - errorString.contains('InvalidImageFormatException') || - errorString.contains('UnhandledExifOrientation') || - errorString.contains('FileSizeTooLargeForMobileIndexing'); + errorString.contains('InvalidImageFormatException') || + errorString.contains('UnhandledExifOrientation') || + errorString.contains('FileSizeTooLargeForMobileIndexing'); if (acceptedIssue) { _logger.severe( '$errorString for fileID ${instruction.file.uploadedFileID} (format $format, type $fileType, size $size), storing empty results so indexing does not get stuck', @@ -592,8 +582,7 @@ class MLService { } void _logStatus() { - final String status = - ''' + final String status = ''' isInternalUser: ${flagService.internalUser} Local indexing: ${localSettings.isMLLocalIndexingEnabled} canRunMLController: $_mlControllerStatus