[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; canRunMLController = event.shouldRun;
if (canRunMLController) { if (canRunMLController) {
_logger.info("MLController allowed running ML, faces indexing starting"); _logger.info(
"MLController allowed running ML, faces indexing starting",
);
unawaited(indexAndClusterAll()); unawaited(indexAndClusterAll());
} else { } else {
_logger.info("MLController stopped running ML, faces indexing paused"); _logger
.info("MLController stopped running ML, faces indexing paused");
pauseIndexing(); pauseIndexing();
} }
}); });
@ -1014,6 +1017,7 @@ class FaceMlService {
file = await getThumbnailForUploadedFile(enteFile); file = await getThumbnailForUploadedFile(enteFile);
} else { } else {
file = await getFile(enteFile, isOrigin: true); file = await getFile(enteFile, isOrigin: true);
// TODO: This is returning null for Pragadees for all files, so something is wrong here!
} }
if (file == null) { if (file == null) {
_logger.warning("Could not get file for $enteFile"); _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:flutter/material.dart";
import "package:intl/intl.dart"; import "package:intl/intl.dart";
import "package:logging/logging.dart";
import "package:photos/core/event_bus.dart"; import "package:photos/core/event_bus.dart";
import 'package:photos/events/embedding_updated_event.dart'; import 'package:photos/events/embedding_updated_event.dart';
import "package:photos/face/db.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/data_util.dart";
import "package:photos/utils/local_settings.dart"; import "package:photos/utils/local_settings.dart";
final _logger = Logger("MachineLearningSettingsPage");
class MachineLearningSettingsPage extends StatefulWidget { class MachineLearningSettingsPage extends StatefulWidget {
const MachineLearningSettingsPage({super.key}); const MachineLearningSettingsPage({super.key});
@ -65,6 +68,7 @@ class _MachineLearningSettingsPageState
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final bool facesFlag = flagService.faceSearchEnabled; final bool facesFlag = flagService.faceSearchEnabled;
_logger.info("On page open, facesFlag: $facesFlag");
return Scaffold( return Scaffold(
body: CustomScrollView( body: CustomScrollView(
primary: false, primary: false,
@ -435,16 +439,22 @@ class FaceRecognitionStatusWidgetState
} }
Future<(int, int, int, double)> getIndexStatus() async { Future<(int, int, int, double)> getIndexStatus() async {
final indexedFiles = await FaceMLDataDB.instance try {
.getIndexedFileCount(minimumMlVersion: faceMlVersion); final indexedFiles = await FaceMLDataDB.instance
final indexableFiles = (await FaceMlService.getIndexableFileIDs()).length; .getIndexedFileCount(minimumMlVersion: faceMlVersion);
final showIndexedFiles = min(indexedFiles, indexableFiles); final indexableFiles = (await FaceMlService.getIndexableFileIDs()).length;
final pendingFiles = max(indexableFiles - indexedFiles, 0); final showIndexedFiles = min(indexedFiles, indexableFiles);
final foundFaces = await FaceMLDataDB.instance.getTotalFaceCount(); final pendingFiles = max(indexableFiles - indexedFiles, 0);
final clusteredFaces = await FaceMLDataDB.instance.getClusteredFaceCount(); final foundFaces = await FaceMLDataDB.instance.getTotalFaceCount();
final clusteringDoneRatio = clusteredFaces / foundFaces; 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 @override

View file

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