From 2c50b84e304a5fe81f22fb4dc0e84f8cccc0760a Mon Sep 17 00:00:00 2001 From: laurenspriem Date: Fri, 30 May 2025 16:55:48 +0530 Subject: [PATCH] Better update in memory cache --- mobile/lib/db/ml/db.dart | 2 ++ .../face_ml/person/person_service.dart | 5 +---- mobile/lib/utils/face/face_box_crop.dart | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mobile/lib/db/ml/db.dart b/mobile/lib/db/ml/db.dart index 322bb90303..a1d2a6ccf1 100644 --- a/mobile/lib/db/ml/db.dart +++ b/mobile/lib/db/ml/db.dart @@ -1286,6 +1286,8 @@ class MLDataDB with SqlDbBase implements IMLDataDB { ]; } + /// WARNING: Better to use the similarly named [putFaceIdCachedForPersonOrCluster] + /// method from face_thumbnail_cache instead! Future putFaceIdCachedForPersonOrCluster( String personOrClusterId, String faceID, diff --git a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart b/mobile/lib/services/machine_learning/face_ml/person/person_service.dart index 025cbc8bf1..e7ca73a4bb 100644 --- a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart +++ b/mobile/lib/services/machine_learning/face_ml/person/person_service.dart @@ -443,10 +443,7 @@ class PersonService { data: person.data.copyWith(avatarFaceId: face.faceID), ); await updatePerson(updatedPerson); - await faceMLDataDB.putFaceIdCachedForPersonOrCluster( - p.remoteID, - face.faceID, - ); + await putFaceIdCachedForPersonOrCluster(p.remoteID, face.faceID); return updatedPerson; } diff --git a/mobile/lib/utils/face/face_box_crop.dart b/mobile/lib/utils/face/face_box_crop.dart index 74fe92e22a..37542dd1f8 100644 --- a/mobile/lib/utils/face/face_box_crop.dart +++ b/mobile/lib/utils/face/face_box_crop.dart @@ -65,6 +65,17 @@ Future checkUsedFaceIDForPersonOrClusterId( return faceIDFromDB; } +Future putFaceIdCachedForPersonOrCluster( + String personOrClusterID, + String faceID, +) async { + await MLDataDB.instance.putFaceIdCachedForPersonOrCluster( + personOrClusterID, + faceID, + ); + _personOrClusterIdToCachedFaceID.put(personOrClusterID, faceID); +} + Future _putCachedCropForFaceID( String faceID, Uint8List data, [ @@ -72,11 +83,7 @@ Future _putCachedCropForFaceID( ]) async { _faceCropCache.put(faceID, data); if (personOrClusterID != null) { - await MLDataDB.instance.putFaceIdCachedForPersonOrCluster( - personOrClusterID, - faceID, - ); - _personOrClusterIdToCachedFaceID.put(personOrClusterID, faceID); + await putFaceIdCachedForPersonOrCluster(personOrClusterID, faceID); } }