[mob] Persist setting for disabling remote fetch

This commit is contained in:
Neeraj Gupta 2024-04-12 16:20:09 +05:30
parent 107b79eae6
commit 5fec61fc1b
3 changed files with 14 additions and 14 deletions

View file

@ -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<void> indexAllImages({withFetching = true}) async {
Future<void> 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();

View file

@ -97,9 +97,9 @@ class _FaceDebugSectionWidgetState extends State<FaceDebugSectionWidget> {
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<FaceDebugSectionWidget> {
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(() {});
}

View file

@ -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<void> toggleRemoteFetch() async {
await _prefs.setBool("remoteFetchEnabled", !remoteFetchEnabled);
}
//#endregion
/// toggleFaceClustering toggles the face clustering setting and returns the new value
Future<bool> toggleFaceClustering() async {
await _prefs.setBool(kEnableFaceClustering, !isFaceClusteringEnabled);