π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Prune orphaned unclustered faces
laurensprieme1428aa25fd3
diff --git a/mobile/apps/photos/lib/db/ml/base.dart b/mobile/apps/photos/lib/db/ml/base.dartindex e84a2fa5b0..db19c2ec65 100644--- a/mobile/apps/photos/lib/db/ml/base.dart+++ b/mobile/apps/photos/lib/db/ml/base.dart@@ -71,6 +71,7 @@ abstract class IMLDataDB<T> {Future<int> getErroredFaceCount();Future<Set<T>> getErroredFileIDs();Future<void> deleteFaceIndexForFiles(List<T> fileIDs);+ Future<void> deleteUnclusteredFaceIndexForFiles(List<T> fileIDs);Future<int> getClusteredOrFacelessFileCount();Future<double> getClusteredToIndexableFilesRatio();Future<int> getUnclusteredFaceCount();diff --git a/mobile/apps/photos/lib/db/ml/db.dart b/mobile/apps/photos/lib/db/ml/db.dartindex 163b747def..9cf00e4d02 100644--- a/mobile/apps/photos/lib/db/ml/db.dart+++ b/mobile/apps/photos/lib/db/ml/db.dart@@ -1251,6 +1251,23 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {await db.execute(sql);}+ @override+ Future<void> deleteUnclusteredFaceIndexForFiles(List<int> fileIDs) async {+ if (fileIDs.isEmpty) return;+ final db = await asyncDB;+ for (final chunk in fileIDs.chunks(_maxSqlBindParamsPerQuery)) {+ final placeholders = List.filled(chunk.length, '?').join(', ');+ await db.execute('''+ DELETE FROM $facesTable+ WHERE $fileIDColumn IN ($placeholders)+ AND NOT EXISTS (+ SELECT 1 FROM $faceClustersTable+ WHERE $faceClustersTable.$faceIDColumn = $facesTable.$faceIDColumn+ )+ ''', chunk);+ }+ }+@overrideFuture<int> getClusteredOrFacelessFileCount() async {final db = await asyncDB;diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart b/mobile/apps/photos/lib/services/machine_learning/ml_service.dartindex 538fe62d66..04ac18b152 100644--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart@@ -731,6 +731,24 @@ class MLService {'and ${missingFileIDs.length} missing fileIDs',);+ if (missingFileIDs.isNotEmpty) {+ await mlDataDB.deleteUnclusteredFaceIndexForFiles(+ missingFileIDs.toList(),+ );+ _logger.info(+ 'Pruned unclustered face data for ${missingFileIDs.length} missing files',+ );+ }++ if (allFaceInfoForClustering.every((face) => face.clusterId != null)) {+ _logger.info('All faces clustered');+ _logger.info(+ 'clusterAllImages() finished, in '+ '${DateTime.now().difference(clusterAllImagesTime).inSeconds} seconds',+ );+ return;+ }+final Map<String, (Uint8List, int)> oldClusterSummaries = await mlDataDB.getAllClusterSummary();