Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Run bg ML without force

Prateek Sunal136d2342dbd7
diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dart
index 9217fea275..b8ec1d0523 100644
--- a/mobile/apps/photos/lib/main.dart
+++ b/mobile/apps/photos/lib/main.dart
@@ -234,7 +234,7 @@ Future<void> _runMinimally(String taskId, TimeLogger tlog) async {
await MLService.instance.init();
await PersonService.init(entityService, MLDataDB.instance, prefs);
mlRunStarted = true;
- await MLService.instance.runAllML(force: true);
+ await MLService.instance.runAllML(force: false);
} finally {
if (!mlRunStarted) {
controller.releaseCompute(ml: true);
diff --git a/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart b/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart
index f59549ed20..0b6f8438a7 100644
--- a/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/compute_controller.dart
@@ -55,6 +55,11 @@ class ComputeController {
bool _waitingToRunML = false;
bool get isDeviceHealthy => _isDeviceHealthy;
+ bool get shouldRunCompute =>
+ _hasCompletedInitialHealthChecks &&
+ _isDeviceHealthy &&
+ _canRunMLGivenUserInteraction() &&
+ !computeBlocked;
void _setDeviceHealth(bool healthy) {
if (_isDeviceHealthy == healthy) return;
@@ -271,7 +276,7 @@ class ComputeController {
return;
}
final shouldRunCompute =
- _isDeviceHealthy && _canRunMLGivenUserInteraction() && !computeBlocked;
+ this.shouldRunCompute;
if (shouldRunCompute != _canRunCompute) {
_canRunCompute = shouldRunCompute;
_logger.info(
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 9516068445..86b6a9ad75 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_service.dart
@@ -131,12 +131,23 @@ class MLService {
pauseIndexingAndClustering();
}
});
+ _syncMlControllerStatusForBg();
_isInitialized = true;
unawaited(_maybePredownloadLocalModels());
_logger.info('init done');
}
+ void _syncMlControllerStatusForBg() {
+ if (!isProcessBg || !hasGrantedMLConsent) {
+ return;
+ }
+ _mlControllerStatus = computeController.shouldRunCompute;
+ _logger.info(
+ "Background init synced MLController status to $_mlControllerStatus",
+ );
+ }
+
Future<void> _maybePredownloadLocalModels() async {
if (isProcessBg) {
return;