Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Delay ML predownload at startup

laurenspriem3b65b177bfa8
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 0806fd3486..81f7392ec1 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
@@ -55,6 +55,9 @@ class MLService {
bool _isIndexingOrClusteringRunning = false;
bool _isRunningML = false;
bool _shouldPauseIndexingAndClustering = false;
+ Timer? _predownloadLocalModelsTimer;
+
+ static const _kPredownloadLocalModelsDelay = Duration(seconds: 6);
bool get isRunningML =>
_isRunningML || memoriesCacheService.isUpdatingMemories;
@@ -83,7 +86,7 @@ class MLService {
/// Only call this function once at app startup, after that you can directly call [runAllML]
Future<void> init() async {
if (_isInitialized) {
- unawaited(_maybePredownloadLocalModels());
+ _schedulePredownloadLocalModels();
return;
}
_logger.info("init called");
@@ -134,7 +137,7 @@ class MLService {
_syncMlControllerStatusForBg();
_isInitialized = true;
- unawaited(_maybePredownloadLocalModels());
+ _schedulePredownloadLocalModels();
_logger.info('init done');
}
@@ -171,6 +174,16 @@ class MLService {
}
}
+ void _schedulePredownloadLocalModels() {
+ if (isProcessBg || _predownloadLocalModelsTimer?.isActive == true) {
+ return;
+ }
+ _predownloadLocalModelsTimer = Timer(_kPredownloadLocalModelsDelay, () {
+ _predownloadLocalModelsTimer = null;
+ unawaited(_maybePredownloadLocalModels());
+ });
+ }
+
bool canFetch() {
if (localSettings.isMLLocalIndexingEnabled) return true;
if (lastRemoteFetch == null) {