π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] simplify ML origin cleanup flow
ashil-pilotd79472878bbb
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart b/mobile/apps/photos/lib/services/machine_learning/ml_service.dartindex 8625d35517..5a50d5bd6e 100644--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart@@ -14,6 +14,7 @@ import "package:photos/db/offline_files_db.dart";import "package:photos/events/compute_control_event.dart";import "package:photos/events/people_changed_event.dart";import "package:photos/main.dart";+import "package:photos/models/file/file_type.dart";import "package:photos/models/ml/clip.dart";import "package:photos/models/ml/face/face.dart";import "package:photos/models/ml/ml_versions.dart";@@ -749,13 +750,16 @@ class MLService {bool actuallyRanML = false;final mlDataDB = _dbForMode(instruction.mode);- MLImageSource? source;+ String? pathToDeleteAfterMLProcessing;try {- source = await getImagePathForML(instruction.file);+ final String filePath = await getImagePathForML(instruction.file);+ if (_shouldDeleteAfterMLProcessing(instruction)) {+ pathToDeleteAfterMLProcessing = filePath;+ }final MLResult? result = await MLIndexingIsolate.instance.analyzeImage(instruction,- source.imagePath,+ filePath,);// Check if there's no result simply because MLController paused indexingif (result == null) {@@ -964,14 +968,14 @@ class MLService {}return false;} finally {- if (source != null && source.shouldDeleteAfterMLProcessing) {+ if (pathToDeleteAfterMLProcessing != null) {try {- await File(source.imagePath).delete();+ await File(pathToDeleteAfterMLProcessing).delete();} on PathNotFoundException {// Already deleted.} catch (e, s) {_logger.warning(- "Failed to delete origin file exported for ML at ${source.imagePath}",+ "Failed to delete origin file exported for ML at $pathToDeleteAfterMLProcessing",e,s,);@@ -980,6 +984,14 @@ class MLService {}}+ bool _shouldDeleteAfterMLProcessing(FileMLInstruction instruction) {+ final file = instruction.file;+ return Platform.isIOS &&+ file.fileType != FileType.video &&+ !file.isRemoteFile &&+ !file.isSharedMediaToAppSandbox;+ }+bool _canRunMLFunction({required String function}) {if (kDebugMode && Platform.isIOS && !_isIndexingOrClusteringRunning) {return true;diff --git a/mobile/apps/photos/lib/utils/ml_util.dart b/mobile/apps/photos/lib/utils/ml_util.dartindex 16c3289b20..829f7a2c87 100644--- a/mobile/apps/photos/lib/utils/ml_util.dart+++ b/mobile/apps/photos/lib/utils/ml_util.dart@@ -696,17 +696,8 @@ Future<int> _getIndexableFileCount({required MLMode mode}) async {return getIndexableFileCount();}-typedef MLImageSource = ({- String imagePath,- bool shouldDeleteAfterMLProcessing,-});--/// Returns the path to use for ML processing of [enteFile], and whether the-/// caller must delete that file afterwards (true only for iOS photo_manager-/// origin exports).-Future<MLImageSource> getImagePathForML(EnteFile enteFile) async {+Future<String> getImagePathForML(EnteFile enteFile) async {String? imagePath;- bool shouldDeleteAfterMLProcessing = false;final stopwatch = Stopwatch()..start();File? file;@@ -734,11 +725,6 @@ Future<MLImageSource> getImagePathForML(EnteFile enteFile) async {trackOriginFetchForUploadOrML.put(enteFile.localID!, true);}file = await getFile(enteFile, isOrigin: true);- shouldDeleteAfterMLProcessing =- Platform.isIOS &&- file != null &&- !enteFile.isRemoteFile &&- !enteFile.isSharedMediaToAppSandbox;} catch (e, s) {_logger.severe("Could not get file for $enteFile", e, s);}@@ -756,10 +742,7 @@ Future<MLImageSource> getImagePathForML(EnteFile enteFile) async {throw CouldNotRetrieveAnyFileData();}- return (- imagePath: imagePath,- shouldDeleteAfterMLProcessing: shouldDeleteAfterMLProcessing,- );+ return imagePath;}bool _shouldRunIndexing(