From 5fec61fc1b2dc2d1d7ccfbff88fdf066961bdcd8 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:20:09 +0530 Subject: [PATCH] [mob] Persist setting for disabling remote fetch --- .../face_ml/face_ml_service.dart | 4 ++-- .../debug/face_debug_section_widget.dart | 16 ++++------------ mobile/lib/utils/local_settings.dart | 8 ++++++++ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart b/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart index 254d5136f..37ba11626 100644 --- a/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart +++ b/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart @@ -510,7 +510,7 @@ class FaceMlService { /// Analyzes all the images in the database with the latest ml version and stores the results in the database. /// /// This function first checks if the image has already been analyzed with the lastest faceMlVersion and stored in the database. If so, it skips the image. - Future indexAllImages({withFetching = true}) async { + Future indexAllImages() async { if (isImageIndexRunning) { _logger.warning("indexAllImages is already running, skipping"); return; @@ -562,7 +562,7 @@ class FaceMlService { for (final f in chunk) { fileIds.add(f.uploadedFileID!); } - if (withFetching) { + if (LocalSettings.instance.remoteFetchEnabled) { try { final EnteWatch? w = kDebugMode ? EnteWatch("face_em_fetch") : null; w?.start(); diff --git a/mobile/lib/ui/settings/debug/face_debug_section_widget.dart b/mobile/lib/ui/settings/debug/face_debug_section_widget.dart index 7a924dacd..17d891b67 100644 --- a/mobile/lib/ui/settings/debug/face_debug_section_widget.dart +++ b/mobile/lib/ui/settings/debug/face_debug_section_widget.dart @@ -97,9 +97,9 @@ class _FaceDebugSectionWidgetState extends State { builder: (context, snapshot) { if (snapshot.hasData) { return CaptionedTextWidget( - title: LocalSettings.instance.isFaceIndexingEnabled - ? "Disable indexing (no fetch) (${snapshot.data!.length})" - : "Enable indexing (${snapshot.data!.length})", + title: LocalSettings.instance.remoteFetchEnabled + ? "Remote fetch Enabled" + : "Remote fetch Disabled", ); } return const SizedBox.shrink(); @@ -110,15 +110,7 @@ class _FaceDebugSectionWidgetState extends State { trailingIconIsMuted: true, onTap: () async { try { - final isEnabled = - await LocalSettings.instance.toggleFaceIndexing(); - if (isEnabled) { - FaceMlService.instance - .indexAllImages(withFetching: false) - .ignore(); - } else { - FaceMlService.instance.pauseIndexing(); - } + await LocalSettings.instance.toggleRemoteFetch(); if (mounted) { setState(() {}); } diff --git a/mobile/lib/utils/local_settings.dart b/mobile/lib/utils/local_settings.dart index 10d1ad57b..8050c1d73 100644 --- a/mobile/lib/utils/local_settings.dart +++ b/mobile/lib/utils/local_settings.dart @@ -84,6 +84,14 @@ class LocalSettings { return isFaceIndexingEnabled; } + //#region todo:(NG) remove this section, only needed for internal testing to see + // if the OS stops the app during indexing + bool get remoteFetchEnabled => _prefs.getBool("remoteFetchEnabled") ?? false; + Future toggleRemoteFetch() async { + await _prefs.setBool("remoteFetchEnabled", !remoteFetchEnabled); + } + //#endregion + /// toggleFaceClustering toggles the face clustering setting and returns the new value Future toggleFaceClustering() async { await _prefs.setBool(kEnableFaceClustering, !isFaceClusteringEnabled);