Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] Create emailToName cache for contacts linked to people

ashilkn03be5540255e
diff --git a/mobile/lib/core/configuration.dart b/mobile/lib/core/configuration.dart
index f71256a61c..e15193a5d3 100644
--- a/mobile/lib/core/configuration.dart
+++ b/mobile/lib/core/configuration.dart
@@ -26,6 +26,7 @@ import 'package:photos/services/collections_service.dart';
import 'package:photos/services/favorites_service.dart';
import "package:photos/services/home_widget_service.dart";
import 'package:photos/services/ignored_files_service.dart';
+import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
import 'package:photos/services/memories_service.dart';
import 'package:photos/services/search_service.dart';
import 'package:photos/services/sync_service.dart';
@@ -216,6 +217,7 @@ class Configuration {
FavoritesService.instance.clearCache();
MemoriesService.instance.clearCache();
SearchService.instance.clearCache();
+ PersonService.instance.clearCache();
unawaited(HomeWidgetService.instance.clearHomeWidget());
Bus.instance.fire(UserLoggedOutEvent());
} else {
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 ee327b776e..3ff47f167f 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
@@ -19,6 +19,7 @@ class PersonService {
final EntityService entityService;
final MLDataDB faceMLDataDB;
final SharedPreferences prefs;
+ final _emailToNameMap = <String, String>{};
PersonService(this.entityService, this.faceMLDataDB, this.prefs);
@@ -40,6 +41,17 @@ class PersonService {
SharedPreferences prefs,
) {
_instance = PersonService(entityService, faceMLDataDB, prefs);
+ _instance!.getPersons().then((value) {
+ for (var person in value) {
+ if (person.data.email != null && person.data.email!.isNotEmpty) {
+ _instance!._emailToNameMap[person.data.email!] = person.data.name;
+ }
+ }
+ });
+ }
+
+ void clearCache() {
+ _emailToNameMap.clear();
}
Future<List<PersonEntity>> getPersons() async {
@@ -178,6 +190,9 @@ class PersonService {
personID: result.id,
clusterID: clusterID,
);
+ if (data.email != null) {
+ _emailToNameMap[data.email!] = data.name;
+ }
return PersonEntity(result.id, data);
}
@@ -251,8 +266,8 @@ class PersonService {
}
Future<void> deletePerson(String personID, {bool onlyMapping = false}) async {
+ final entity = await getPerson(personID);
if (onlyMapping) {
- final PersonEntity? entity = await getPerson(personID);
if (entity == null) {
return;
}
@@ -265,9 +280,19 @@ class PersonService {
);
await faceMLDataDB.removePerson(personID);
justName.data.logStats();
+
+ if (entity.data.email != null) {
+ _emailToNameMap.remove(entity.data.email!);
+ }
} else {
await entityService.deleteEntry(personID);
await faceMLDataDB.removePerson(personID);
+
+ if (entity != null) {
+ if (entity.data.email != null) {
+ _emailToNameMap.remove(entity.data.email!);
+ }
+ }
}
// fire PeopleChangeEvent
@@ -427,7 +452,14 @@ class PersonService {
email: email,
),
);
- await updatePerson(updatedPerson);
+ await updatePerson(updatedPerson).then((value) {
+ if (email != null) {
+ _emailToNameMap[email] = updatedPerson.data.name;
+ }
+ if (name != null && updatedPerson.data.email != null) {
+ _emailToNameMap[updatedPerson.data.email!] = name;
+ }
+ });
return updatedPerson;
}