π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Prune resolved ML error markers
laurenspriem543052956951
diff --git a/mobile/apps/photos/lib/db/ml/base.dart b/mobile/apps/photos/lib/db/ml/base.dartindex caa8ae3341..f19af5c699 100644--- a/mobile/apps/photos/lib/db/ml/base.dart+++ b/mobile/apps/photos/lib/db/ml/base.dart@@ -70,6 +70,7 @@ abstract class IMLDataDB<T> {Future<int> getTotalFaceCount();Future<int> getErroredFaceCount();Future<Set<T>> getErroredFileIDs();+ Future<void> pruneResolvedFaceErrorResults(List<T> fileIDs);Future<Set<T>> getFileIDsWithErrorResults(List<T> fileIDs);Future<void> deleteFaceIndexForFiles(List<T> fileIDs);Future<void> deleteUnclusteredFaceIndexForFiles(List<T> fileIDs);diff --git a/mobile/apps/photos/lib/db/ml/db.dart b/mobile/apps/photos/lib/db/ml/db.dartindex 1665e5f4e1..9e1ab6ffa6 100644--- a/mobile/apps/photos/lib/db/ml/db.dart+++ b/mobile/apps/photos/lib/db/ml/db.dart@@ -1241,6 +1241,26 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {return maps.map((e) => e[fileIDColumn] as int).toSet();}+ @override+ Future<void> pruneResolvedFaceErrorResults(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 $faceScore < 0+ AND EXISTS (+ SELECT 1 FROM $facesTable AS successful+ WHERE successful.$fileIDColumn = $facesTable.$fileIDColumn+ AND successful.$faceScore >= 0+ AND successful.$mlVersionColumn >= $facesTable.$mlVersionColumn+ )+ ''', chunk);+ }+ }+@overrideFuture<Set<int>> getFileIDsWithErrorResults(List<int> fileIDs) async {if (fileIDs.isEmpty) return {};@@ -1251,8 +1271,15 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {final placeholders = List.filled(chunk.length, '?').join(', ');final rows = await db.getAll('''- SELECT $fileIDColumn FROM $facesTable- WHERE $fileIDColumn IN ($placeholders) AND $faceScore < 0+ SELECT failed.$fileIDColumn FROM $facesTable AS failed+ WHERE failed.$fileIDColumn IN ($placeholders)+ AND failed.$faceScore < 0+ AND NOT EXISTS (+ SELECT 1 FROM $facesTable AS successful+ WHERE successful.$fileIDColumn = failed.$fileIDColumn+ AND successful.$faceScore >= 0+ AND successful.$mlVersionColumn >= failed.$mlVersionColumn+ )UNIONSELECT $fileIDColumn FROM $clipTableWHERE $fileIDColumn IN ($placeholders) AND LENGTH($embeddingColumn) = 0diff --git a/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart b/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dartindex 6b491af0a5..83f6b9c944 100644--- a/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart+++ b/mobile/apps/photos/lib/ui/settings/ml/machine_learning_settings_page.dart@@ -41,6 +41,7 @@ class _MachineLearningSettingsPageStateTimer? _advancedOptionsTimer;bool _hasAcknowledgedMLConsent = false;bool _hasHandledDisabledExit = false;+ bool _mlDecryptionRecordsReady = false;@overridevoid initState() {@@ -67,26 +68,22 @@ class _MachineLearningSettingsPageStateFuture<void> _pruneMlDecryptionRecords() async {final recordedFileIDs = mlDecryptionRecordStore.fileIDs;- if (recordedFileIDs.isEmpty) {- mlDecryptionRecordStore.logFileIDs();- return;- }try {- final existingFiles = await FilesDB.instance.getFileIDToFileFromIDs(- recordedFileIDs,- );- final errorResultFileIDs = await MLDataDB.instance- .getFileIDsWithErrorResults(recordedFileIDs);- final staleFileIDs = recordedFileIDs- .where(- (fileID) =>- !existingFiles.containsKey(fileID) ||- !errorResultFileIDs.contains(fileID),- )- .toSet();- await mlDecryptionRecordStore.removeAll(staleFileIDs);- if (staleFileIDs.isNotEmpty && mounted) {- setState(() {});+ if (recordedFileIDs.isNotEmpty) {+ await MLDataDB.instance.pruneResolvedFaceErrorResults(recordedFileIDs);+ final existingFiles = await FilesDB.instance.getFileIDToFileFromIDs(+ recordedFileIDs,+ );+ final errorResultFileIDs = await MLDataDB.instance+ .getFileIDsWithErrorResults(recordedFileIDs);+ final staleFileIDs = recordedFileIDs+ .where(+ (fileID) =>+ !existingFiles.containsKey(fileID) ||+ !errorResultFileIDs.contains(fileID),+ )+ .toSet();+ await mlDecryptionRecordStore.removeAll(staleFileIDs);}} catch (error, stackTrace) {_logger.warning(@@ -96,6 +93,9 @@ class _MachineLearningSettingsPageState);} finally {mlDecryptionRecordStore.logFileIDs();+ if (mounted) {+ setState(() => _mlDecryptionRecordsReady = true);+ }}}@@ -374,7 +374,7 @@ class _MachineLearningSettingsPageStateonlyIndexingModels: true,) ||!localSettings.isMLLocalIndexingEnabled- ? const MLStatusWidget()+ ? MLStatusWidget(showDecryptionWarning: _mlDecryptionRecordsReady): const ModelLoadingState(),],);@@ -490,7 +490,9 @@ class _ModelLoadingStateState extends State<ModelLoadingState> {}class MLStatusWidget extends StatefulWidget {- const MLStatusWidget({super.key});+ final bool showDecryptionWarning;++ const MLStatusWidget({required this.showDecryptionWarning, super.key});@overrideState<MLStatusWidget> createState() => MLStatusWidgetState();@@ -524,7 +526,9 @@ class MLStatusWidgetState extends State<MLStatusWidget> {@overrideWidget build(BuildContext context) {final colors = context.componentColors;- final decryptionIssueCount = mlDecryptionRecordStore.count;+ final decryptionIssueCount = widget.showDecryptionWarning+ ? mlDecryptionRecordStore.count+ : 0;return Column(children: [Padding(