Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Fix startup ML hydration regressions

laurenspriemba188313dd59
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 8af594ec7c..62e2bd1e10 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
@@ -219,7 +219,15 @@ class MLService {
);
return;
}
- await hydrateRemoteEmbeddingsForOwnedFiles(reason: "startup");
+ try {
+ await hydrateRemoteEmbeddingsForOwnedFiles(reason: "startup");
+ } catch (e, s) {
+ _logger.warning(
+ "Skipping startup-owned remote ML hydration because owned hydration failed",
+ e,
+ s,
+ );
+ }
}
Future<void> hydrateRemoteEmbeddingsForOwnedFiles({
@@ -238,7 +246,7 @@ class MLService {
);
return existing;
}
- final future = _hydrateRemoteEmbeddingsForOwnedFilesInternal(
+ final future = _runOwnedRemoteHydrationSafely(
reason: reason,
);
_ownedRemoteHydrationFuture = future;
@@ -251,6 +259,16 @@ class MLService {
}
}
+ Future<void> _runOwnedRemoteHydrationSafely({
+ required String reason,
+ }) async {
+ try {
+ await _hydrateRemoteEmbeddingsForOwnedFilesInternal(reason: reason);
+ } catch (e, s) {
+ _logger.warning("Owned remote ML hydration ($reason) failed", e, s);
+ }
+ }
+
Future<void> _hydrateRemoteEmbeddingsForOwnedFilesInternal({
required String reason,
}) async {
@@ -276,7 +294,15 @@ class MLService {
_logger.info(
"Waiting for owned remote ML hydration to finish before indexing",
);
- await existing;
+ try {
+ await existing;
+ } catch (e, s) {
+ _logger.warning(
+ "Owned remote ML hydration failed while indexing was waiting, continuing",
+ e,
+ s,
+ );
+ }
}
bool canFetch() {
diff --git a/mobile/apps/photos/lib/utils/ml_util.dart b/mobile/apps/photos/lib/utils/ml_util.dart
index 5d73cb7146..dc177db281 100644
--- a/mobile/apps/photos/lib/utils/ml_util.dart
+++ b/mobile/apps/photos/lib/utils/ml_util.dart
@@ -81,6 +81,16 @@ class RemoteMLHydrationSummary {
});
}
+class _OnlineMLIndexingCandidates {
+ final List<FileMLInstruction> matched;
+ final List<FileMLInstruction> unmatched;
+
+ const _OnlineMLIndexingCandidates({
+ required this.matched,
+ required this.unmatched,
+ });
+}
+
Future<IndexStatus> getIndexStatus() async {
try {
final MLMode mode = isOfflineMode ? MLMode.offline : MLMode.online;
@@ -116,9 +126,8 @@ Future<IndexStatus> getIndexStatus() async {
// when local indexing is disabled.
int _lastFetchTimeForOthersIndexed = 0;
-/// Return a list of file instructions for files that should be indexed for ML
-Future<List<FileMLInstruction>> getFilesForMlIndexing() async {
- _logger.info('getFilesForMlIndexing called');
+Future<_OnlineMLIndexingCandidates>
+ _getOnlineFilesForMlIndexingCandidates() async {
final mlDataDB = MLDataDB.instance;
final time = DateTime.now();
// Get indexed fileIDs for each ML service
@@ -199,14 +208,15 @@ Future<List<FileMLInstruction>> getFilesForMlIndexing() async {
if (!shouldRunFaces && !shouldRunClip && !shouldRunPets) {
continue;
}
- final instruction = FileMLInstruction(
- file: enteFile,
- mode: MLMode.online,
- shouldRunFaces: shouldRunFaces,
- shouldRunClip: shouldRunClip,
- shouldRunPets: shouldRunPets,
+ hiddenFilesToIndex.add(
+ FileMLInstruction(
+ file: enteFile,
+ mode: MLMode.online,
+ shouldRunFaces: shouldRunFaces,
+ shouldRunClip: shouldRunClip,
+ shouldRunPets: shouldRunPets,
+ ),
);
- hiddenFilesToIndex.add(instruction);
}
final sortedBylocalID = <FileMLInstruction>[
...filesWithLocalID,
@@ -220,11 +230,21 @@ Future<List<FileMLInstruction>> getFilesForMlIndexing() async {
_logger.info(
"Getting list of ${sortedBylocalID.length} files to index for ML took ${DateTime.now().difference(time).inMilliseconds} ms",
);
+ return _OnlineMLIndexingCandidates(
+ matched: splitResult.matched,
+ unmatched: splitResult.unmatched,
+ );
+}
+
+/// Return a list of file instructions for files that should be indexed for ML
+Future<List<FileMLInstruction>> getFilesForMlIndexing() async {
+ _logger.info('getFilesForMlIndexing called');
+ final candidateSplit = await _getOnlineFilesForMlIndexingCandidates();
if (!localSettings.isMLLocalIndexingEnabled) {
final time = DateTime.now().millisecondsSinceEpoch;
if ((time - _lastFetchTimeForOthersIndexed) > 1000 * 60 * 60 * 24) {
final filesOwnedByOthers = [];
- for (final instruction in splitResult.unmatched) {
+ for (final instruction in candidateSplit.unmatched) {
if (instruction.file.isUploaded && !instruction.file.isOwner) {
filesOwnedByOthers.add(instruction);
}
@@ -233,11 +253,11 @@ Future<List<FileMLInstruction>> getFilesForMlIndexing() async {
_logger.info(
'Checking index for ${filesOwnedByOthers.length} owned by others',
);
- return [...splitResult.matched, ...filesOwnedByOthers];
+ return [...candidateSplit.matched, ...filesOwnedByOthers];
}
- return splitResult.matched;
+ return candidateSplit.matched;
}
- return [...splitResult.matched, ...splitResult.unmatched];
+ return [...candidateSplit.matched, ...candidateSplit.unmatched];
}
Future<List<FileMLInstruction>> getOfflineFilesForMlIndexing() async {
@@ -373,19 +393,9 @@ Stream<List<FileMLInstruction>> fetchEmbeddingsAndInstructions(
Future<RemoteMLHydrationSummary> hydrateOwnedRemoteMLData({
required MLDataDB mlDataDB,
}) async {
- final filesWithRemoteML = await mlDataDB.getFileIDsWithFDData(
- type: DataType.mlData,
- );
- if (filesWithRemoteML.isEmpty) {
- return const RemoteMLHydrationSummary();
- }
-
- final filesToIndex = await getFilesForMlIndexing();
- final ownedCandidates = filesToIndex.where((instruction) {
- final uploadedFileID = instruction.file.uploadedFileID;
- return uploadedFileID != null &&
- instruction.file.isOwner &&
- filesWithRemoteML.contains(uploadedFileID) &&
+ final candidateSplit = await _getOnlineFilesForMlIndexingCandidates();
+ final ownedCandidates = candidateSplit.matched.where((instruction) {
+ return instruction.file.isOwner &&
(instruction.shouldRunFaces || instruction.shouldRunClip);
}).toList();
if (ownedCandidates.isEmpty) {