Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Gate startup ML hydration threshold

laurenspriem633f3b51b4ee
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 937400cf3b..c317ba0aa9 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
@@ -44,6 +44,7 @@ class MLService {
int? lastRemoteFetch;
static const int _kRemoteFetchCooldownOnLite = 1000 * 60 * 5;
+ static const int _kStartupOwnedRemoteHydrationMissingFileThreshold = 200;
Future<void>? _ownedRemoteHydrationFuture;
bool _hasScheduledStartupOwnedRemoteHydration = false;
@@ -202,7 +203,11 @@ class MLService {
return;
}
try {
- await hydrateRemoteEmbeddingsForOwnedFiles(reason: "startup");
+ await hydrateRemoteEmbeddingsForOwnedFiles(
+ reason: "startup",
+ skipHydrationIfCandidateFileCountAtMost:
+ _kStartupOwnedRemoteHydrationMissingFileThreshold,
+ );
} catch (e, s) {
_logger.warning(
"Skipping startup-owned remote ML hydration because owned hydration failed",
@@ -214,6 +219,7 @@ class MLService {
Future<void> hydrateRemoteEmbeddingsForOwnedFiles({
required String reason,
+ int? skipHydrationIfCandidateFileCountAtMost,
}) async {
if (isProcessBg ||
isOfflineMode ||
@@ -230,6 +236,8 @@ class MLService {
}
final future = _runOwnedRemoteHydrationSafely(
reason: reason,
+ skipHydrationIfCandidateFileCountAtMost:
+ skipHydrationIfCandidateFileCountAtMost,
);
_ownedRemoteHydrationFuture = future;
try {
@@ -243,9 +251,14 @@ class MLService {
Future<void> _runOwnedRemoteHydrationSafely({
required String reason,
+ int? skipHydrationIfCandidateFileCountAtMost,
}) async {
try {
- await _hydrateRemoteEmbeddingsForOwnedFilesInternal(reason: reason);
+ await _hydrateRemoteEmbeddingsForOwnedFilesInternal(
+ reason: reason,
+ skipHydrationIfCandidateFileCountAtMost:
+ skipHydrationIfCandidateFileCountAtMost,
+ );
} catch (e, s) {
_logger.warning("Owned remote ML hydration ($reason) failed", e, s);
}
@@ -253,14 +266,27 @@ class MLService {
Future<void> _hydrateRemoteEmbeddingsForOwnedFilesInternal({
required String reason,
+ int? skipHydrationIfCandidateFileCountAtMost,
}) async {
- final summary = await hydrateOwnedRemoteMLData(mlDataDB: MLDataDB.instance);
+ final summary = await hydrateOwnedRemoteMLData(
+ mlDataDB: MLDataDB.instance,
+ skipHydrationIfCandidateFileCountAtMost:
+ skipHydrationIfCandidateFileCountAtMost,
+ );
if (summary.candidateFiles == 0) {
_logger.info(
"Skipping owned remote ML hydration ($reason): no owned files need remote hydration",
);
return;
}
+ if (summary.skippedDueToCandidateThreshold) {
+ _logger.info(
+ "Skipping owned remote ML hydration ($reason): only ${summary.candidateFiles} "
+ "owned files are missing remote ML data (threshold: > "
+ "$skipHydrationIfCandidateFileCountAtMost)",
+ );
+ return;
+ }
_logger.info(
"Owned remote ML hydration ($reason) finished for ${summary.candidateFiles} files "
"(faces hydrated: ${summary.hydratedFaces}, clip hydrated: ${summary.hydratedClips}, "
diff --git a/mobile/apps/photos/lib/utils/ml_util.dart b/mobile/apps/photos/lib/utils/ml_util.dart
index 53550d47df..f49dd00f52 100644
--- a/mobile/apps/photos/lib/utils/ml_util.dart
+++ b/mobile/apps/photos/lib/utils/ml_util.dart
@@ -72,12 +72,14 @@ class RemoteMLHydrationSummary {
final int hydratedFaces;
final int hydratedClips;
final int remainingLocalMl;
+ final bool skippedDueToCandidateThreshold;
const RemoteMLHydrationSummary({
this.candidateFiles = 0,
this.hydratedFaces = 0,
this.hydratedClips = 0,
this.remainingLocalMl = 0,
+ this.skippedDueToCandidateThreshold = false,
});
}
@@ -394,6 +396,7 @@ Stream<List<FileMLInstruction>> fetchEmbeddingsAndInstructions(
Future<RemoteMLHydrationSummary> hydrateOwnedRemoteMLData({
required MLDataDB mlDataDB,
+ int? skipHydrationIfCandidateFileCountAtMost,
}) async {
final candidateSplit = await _getOnlineFilesForMlIndexingCandidates();
final ownedCandidates = candidateSplit.matched.where((instruction) {
@@ -403,6 +406,14 @@ Future<RemoteMLHydrationSummary> hydrateOwnedRemoteMLData({
if (ownedCandidates.isEmpty) {
return const RemoteMLHydrationSummary();
}
+ if (skipHydrationIfCandidateFileCountAtMost != null &&
+ ownedCandidates.length <= skipHydrationIfCandidateFileCountAtMost) {
+ return RemoteMLHydrationSummary(
+ candidateFiles: ownedCandidates.length,
+ remainingLocalMl: ownedCandidates.length,
+ skippedDueToCandidateThreshold: true,
+ );
+ }
int hydratedFaces = 0;
int hydratedClips = 0;