[mob][photos] Logging

This commit is contained in:
laurenspriem 2024-05-21 16:56:00 +05:30
parent d235ff1035
commit 71d3427879
3 changed files with 47 additions and 28 deletions

View file

@ -143,10 +143,13 @@ class FaceMlService {
}
canRunMLController = event.shouldRun;
if (canRunMLController) {
_logger.info("MLController allowed running ML, faces indexing starting");
_logger.info(
"MLController allowed running ML, faces indexing starting",
);
unawaited(indexAndClusterAll());
} else {
_logger.info("MLController stopped running ML, faces indexing paused");
_logger
.info("MLController stopped running ML, faces indexing paused");
pauseIndexing();
}
});
@ -1014,6 +1017,7 @@ class FaceMlService {
file = await getThumbnailForUploadedFile(enteFile);
} else {
file = await getFile(enteFile, isOrigin: true);
// TODO: This is returning null for Pragadees for all files, so something is wrong here!
}
if (file == null) {
_logger.warning("Could not get file for $enteFile");

View file

@ -3,6 +3,7 @@ import "dart:math" show max, min;
import "package:flutter/material.dart";
import "package:intl/intl.dart";
import "package:logging/logging.dart";
import "package:photos/core/event_bus.dart";
import 'package:photos/events/embedding_updated_event.dart';
import "package:photos/face/db.dart";
@ -26,6 +27,8 @@ import "package:photos/ui/components/toggle_switch_widget.dart";
import "package:photos/utils/data_util.dart";
import "package:photos/utils/local_settings.dart";
final _logger = Logger("MachineLearningSettingsPage");
class MachineLearningSettingsPage extends StatefulWidget {
const MachineLearningSettingsPage({super.key});
@ -65,6 +68,7 @@ class _MachineLearningSettingsPageState
@override
Widget build(BuildContext context) {
final bool facesFlag = flagService.faceSearchEnabled;
_logger.info("On page open, facesFlag: $facesFlag");
return Scaffold(
body: CustomScrollView(
primary: false,
@ -435,16 +439,22 @@ class FaceRecognitionStatusWidgetState
}
Future<(int, int, int, double)> getIndexStatus() async {
final indexedFiles = await FaceMLDataDB.instance
.getIndexedFileCount(minimumMlVersion: faceMlVersion);
final indexableFiles = (await FaceMlService.getIndexableFileIDs()).length;
final showIndexedFiles = min(indexedFiles, indexableFiles);
final pendingFiles = max(indexableFiles - indexedFiles, 0);
final foundFaces = await FaceMLDataDB.instance.getTotalFaceCount();
final clusteredFaces = await FaceMLDataDB.instance.getClusteredFaceCount();
final clusteringDoneRatio = clusteredFaces / foundFaces;
try {
final indexedFiles = await FaceMLDataDB.instance
.getIndexedFileCount(minimumMlVersion: faceMlVersion);
final indexableFiles = (await FaceMlService.getIndexableFileIDs()).length;
final showIndexedFiles = min(indexedFiles, indexableFiles);
final pendingFiles = max(indexableFiles - indexedFiles, 0);
final foundFaces = await FaceMLDataDB.instance.getTotalFaceCount();
final clusteredFaces =
await FaceMLDataDB.instance.getClusteredFaceCount();
final clusteringDoneRatio = clusteredFaces / foundFaces;
return (showIndexedFiles, pendingFiles, foundFaces, clusteringDoneRatio);
return (showIndexedFiles, pendingFiles, foundFaces, clusteringDoneRatio);
} catch (e, s) {
_logger.severe('Error getting face recognition status', e, s);
rethrow;
}
}
@override

View file

@ -37,25 +37,30 @@ Future<File?> getFile(
bool isOrigin = false,
} // only relevant for live photos
) async {
if (file.isRemoteFile) {
return getFileFromServer(file, liveVideo: liveVideo);
} else {
final String key = file.tag + liveVideo.toString() + isOrigin.toString();
final cachedFile = FileLruCache.get(key);
if (cachedFile == null) {
final diskFile = await _getLocalDiskFile(
file,
liveVideo: liveVideo,
isOrigin: isOrigin,
);
// do not cache origin file for IOS as they are immediately deleted
// after usage
if (!(isOrigin && Platform.isIOS) && diskFile != null) {
FileLruCache.put(key, diskFile);
try {
if (file.isRemoteFile) {
return getFileFromServer(file, liveVideo: liveVideo);
} else {
final String key = file.tag + liveVideo.toString() + isOrigin.toString();
final cachedFile = FileLruCache.get(key);
if (cachedFile == null) {
final diskFile = await _getLocalDiskFile(
file,
liveVideo: liveVideo,
isOrigin: isOrigin,
);
// do not cache origin file for IOS as they are immediately deleted
// after usage
if (!(isOrigin && Platform.isIOS) && diskFile != null) {
FileLruCache.put(key, diskFile);
}
return diskFile;
}
return diskFile;
return cachedFile;
}
return cachedFile;
} catch (e, s) {
_logger.warning("Failed to get file", e, s);
return null;
}
}