π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Manual tagging infra
laurenspriem13d9c202c5c1
diff --git a/mobile/apps/photos/lib/models/ml/face/person.dart b/mobile/apps/photos/lib/models/ml/face/person.dartindex ff2d28a9d7..54df3b6acc 100644--- a/mobile/apps/photos/lib/models/ml/face/person.dart+++ b/mobile/apps/photos/lib/models/ml/face/person.dart@@ -58,6 +58,7 @@ class PersonData {String? avatarFaceID;List<ClusterInfo> assigned = List<ClusterInfo>.empty();List<String> rejectedFaceIDs = List<String>.empty();+ List<int> manuallyAssigned = List<int>.empty();/// string formatted in `yyyy-MM-dd`final String? birthDate;@@ -78,6 +79,7 @@ class PersonData {required this.name,this.assigned = const <ClusterInfo>[],this.rejectedFaceIDs = const <String>[],+ this.manuallyAssigned = const <int>[],this.avatarFaceID,this.isHidden = false,this.isPinned = false,@@ -99,6 +101,7 @@ class PersonData {String? email,int? userID,List<String>? rejectedFaceIDs,+ List<int>? manuallyAssigned,}) {return PersonData(name: name ?? this.name,@@ -112,6 +115,8 @@ class PersonData {userID: userID ?? this.userID,rejectedFaceIDs:rejectedFaceIDs ?? List<String>.from(this.rejectedFaceIDs),+ manuallyAssigned:+ manuallyAssigned ?? List<int>.from(this.manuallyAssigned),);}@@ -126,6 +131,7 @@ class PersonData {}sb.writeln('Assigned: ${assigned.length} withFaces $assignedCount');sb.writeln('Rejected faceIDs: ${rejectedFaceIDs.length}');+ sb.writeln('Manual fileIDs: ${manuallyAssigned.length}');for (var cluster in assigned) {sb.writeln('Cluster: ${cluster.id} - ${cluster.faces.length}');}@@ -144,6 +150,7 @@ class PersonData {'birthDate': birthDate,'email': email,'userID': userID,+ 'manuallyAssigned': manuallyAssigned,};// fromJson@@ -164,10 +171,21 @@ class PersonData {: List<String>.from(json['rejectedFaceIDs'],);+ final manuallyAssigned = (json['manuallyAssigned'] == null ||+ json['manuallyAssigned'].length == 0 ||+ json['manuallyAssigned'] is! Iterable)+ ? <int>[]+ : List<int>.from(+ (json['manuallyAssigned'] as Iterable<dynamic>).map<int?>((value) {+ if (value is num) return value.toInt();+ return int.tryParse(value.toString());+ }).whereType<int>(),+ );return PersonData(name: json['name'] as String,assigned: assigned,rejectedFaceIDs: rejectedFaceIDs,+ manuallyAssigned: manuallyAssigned,avatarFaceID: json['avatarFaceID'] as String?,isHidden: json['isHidden'] as bool? ?? false,isPinned: json['isPinned'] as bool? ?? false,diff --git a/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart b/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dartindex 3aeca70f11..fc231dd31f 100644--- a/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart+++ b/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart@@ -16,7 +16,6 @@ import 'package:photos/models/ml/face/face.dart';import "package:photos/models/ml/face/person.dart";import "package:photos/service_locator.dart";import "package:photos/services/entity_service.dart";-import "package:photos/services/search_service.dart";import "package:photos/utils/face/face_thumbnail_cache.dart";import "package:shared_preferences/shared_preferences.dart";@@ -153,25 +152,6 @@ class PersonService {return map;}- Future<List<EnteFile>> loadPersonFiles(String personID) async {- final result = await SearchService.instance.getClusterFilesForPersonID(- personID,- );- if (result.isEmpty) {- logger.severe(- "No files found for person with id $personID, can't load files",- );- return [];- }- final Set<EnteFile> resultFiles = {};- for (final e in result.entries) {- resultFiles.addAll(e.value);- }- final List<EnteFile> sortedFiles = List<EnteFile>.from(resultFiles);- sortedFiles.sort((a, b) => b.creationTime!.compareTo(a.creationTime!));- return sortedFiles;- }-Future<void> reconcileClusters() async {final EnteWatch? w = kDebugMode ? EnteWatch("reconcileClusters") : null;w?.start();diff --git a/mobile/apps/photos/lib/services/people_home_widget_service.dart b/mobile/apps/photos/lib/services/people_home_widget_service.dartindex 759a845c20..f2a9b2ab39 100644--- a/mobile/apps/photos/lib/services/people_home_widget_service.dart+++ b/mobile/apps/photos/lib/services/people_home_widget_service.dart@@ -179,11 +179,10 @@ class PeopleHomeWidgetService {forceCustomPageRoute: true,).ignore();- final clusterFiles =- await SearchService.instance.getClusterFilesForPersonID(+ final files = await SearchService.instance.getFilesForPersonID(personId,+ sortOnTime: false,);- final files = clusterFiles.entries.expand((e) => e.value).toList();routeToPage(context,@@ -276,9 +275,10 @@ class PeopleHomeWidgetService {final Map<String, (String, Iterable<EnteFile>)> peopleFiles = {};final persons = await PersonService.instance.getCertainPersons(personIds);for (final person in persons) {- final clusterFiles = await SearchService.instance- .getClusterFilesForPersonID(person.remoteID);- final files = clusterFiles.entries.expand((e) => e.value).toList();+ final files = await SearchService.instance.getFilesForPersonID(+ person.remoteID,+ sortOnTime: false,+ );if (files.isEmpty) {_logger.warning("No files found for person: ${person.data.name}");continue;diff --git a/mobile/apps/photos/lib/services/search_service.dart b/mobile/apps/photos/lib/services/search_service.dartindex b8d7b9ba6e..b49e42567c 100644--- a/mobile/apps/photos/lib/services/search_service.dart+++ b/mobile/apps/photos/lib/services/search_service.dart@@ -751,6 +751,59 @@ class SearchService {return clusterIDToFiles;}+ Future<List<EnteFile>> getFilesForPersonID(+ String personID, {+ bool includeManualAssigned = true,+ bool sortOnTime = true,+ }) async {+ final allFiles = await getAllFilesForSearch();+ final uploadedIdToFile = <int, EnteFile>{};+ for (final file in allFiles) {+ final uploadedID = file.uploadedFileID;+ if (uploadedID != null && !uploadedIdToFile.containsKey(uploadedID)) {+ uploadedIdToFile[uploadedID] = file;+ }+ }+ final Map<int, Set<String>> fileIdToClusterID =+ await mlDataDB.getFileIdToClusterIDSet(personID);+ final files = <EnteFile>[];+ final addedFileIDs = <int>{};++ for (final entry in fileIdToClusterID.entries) {+ final file = uploadedIdToFile[entry.key];+ if (file == null) {+ continue;+ }+ if (addedFileIDs.add(entry.key)) {+ files.add(file);+ }+ }+ if (includeManualAssigned) {+ final person = await PersonService.instance.getPerson(personID);+ if (person != null) {+ final manualIDs = person.data.manuallyAssigned.toSet();+ if (manualIDs.isNotEmpty) {+ for (final manualID in manualIDs) {+ if (addedFileIDs.contains(manualID)) {+ continue;+ }+ final file = uploadedIdToFile[manualID];+ if (file != null) {+ files.add(file);+ addedFileIDs.add(manualID);+ }+ }+ }+ }+ }+ if (sortOnTime) {+ files.sort(+ (a, b) => (b.creationTime ?? 0).compareTo(a.creationTime ?? 0),+ );+ }+ return files;+ }+Future<List<GenericSearchResult>> getAllFace(int? limit, {required int minClusterSize,@@ -766,30 +819,63 @@ class SearchService {final List<GenericSearchResult> facesResult = [];final Map<String, List<EnteFile>> clusterIdToFiles = {};final Map<String, List<EnteFile>> personIdToFiles = {};+ final Map<String, Set<int>> personIdToFileIds = {};final allFiles = await getAllFilesForSearch();- for (final f in allFiles) {- if (!fileIdToClusterID.containsKey(f.uploadedFileID ?? -1)) {+ final Map<int, EnteFile> uploadedIdToFile = {};+ for (final file in allFiles) {+ final uploadedID = file.uploadedFileID;+ if (uploadedID != null && !uploadedIdToFile.containsKey(uploadedID)) {+ uploadedIdToFile[uploadedID] = file;+ }+ }++ for (final entry in fileIdToClusterID.entries) {+ final file = uploadedIdToFile[entry.key];+ if (file == null) {continue;}- final clusterIds = fileIdToClusterID[f.uploadedFileID ?? -1]!;+ final clusterIds = entry.value;for (final cluster in clusterIds) {final PersonEntity? p =personIdToPerson[clusterIDToPersonID[cluster] ?? ""];if (p != null) {- if (personIdToFiles.containsKey(p.remoteID)) {- personIdToFiles[p.remoteID]!.add(f);- } else {- personIdToFiles[p.remoteID] = [f];- }+ final filesForPerson =+ personIdToFiles.putIfAbsent(p.remoteID, () => []);+ filesForPerson.add(file);+ final fileIdsForPerson =+ personIdToFileIds.putIfAbsent(p.remoteID, () => <int>{});+ fileIdsForPerson.add(entry.key);} else {if (clusterIdToFiles.containsKey(cluster)) {- clusterIdToFiles[cluster]!.add(f);+ clusterIdToFiles[cluster]!.add(file);} else {- clusterIdToFiles[cluster] = [f];+ clusterIdToFiles[cluster] = [file];}}}}++ for (final entry in personIdToPerson.entries) {+ final personID = entry.key;+ final manualIDs = entry.value.data.manuallyAssigned.toSet();+ if (manualIDs.isEmpty) continue;++ final filesForPerson =+ personIdToFiles.putIfAbsent(personID, () => <EnteFile>[]);+ final idSet = personIdToFileIds.putIfAbsent(personID, () => <int>{});++ for (final manualID in manualIDs) {+ if (idSet.contains(manualID)) {+ continue;+ }+ final file = uploadedIdToFile[manualID];+ if (file != null) {+ filesForPerson.add(file);+ idSet.add(manualID);+ }+ }+ }+// get sorted personId by files countfinal sortedPersonIds = personIdToFiles.keys.toList()..sort(diff --git a/mobile/apps/photos/lib/services/smart_albums_service.dart b/mobile/apps/photos/lib/services/smart_albums_service.dartindex a967dbd618..199925d390 100644--- a/mobile/apps/photos/lib/services/smart_albums_service.dart+++ b/mobile/apps/photos/lib/services/smart_albums_service.dart@@ -143,11 +143,10 @@ class SmartAlbumsService {continue;}- final fileIds = (await SearchService.instance- .getClusterFilesForPersonID(personId))- .entries- .expand((e) => e.value)- .toList()+ final fileIds = (await SearchService.instance.getFilesForPersonID(+ personId,+ sortOnTime: false,+ ))..removeWhere((e) =>e.uploadedFileID == null ||diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dartindex 40acbf7aa8..756a77908b 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart@@ -9,6 +9,7 @@ import "package:photos/models/file_load_result.dart";import "package:photos/models/ml/face/person.dart";import "package:photos/models/selected_files.dart";import "package:photos/services/machine_learning/face_ml/person/person_service.dart";+import "package:photos/services/search_service.dart";import "package:photos/theme/colors.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/components/bottom_of_title_bar_widget.dart";@@ -49,8 +50,11 @@ class PickPersonCoverPhotoWidget extends StatelessWidget {});Future<FileLoadResult> loadPersonFiles() async {- final sortedFiles =- await PersonService.instance.loadPersonFiles(personEntity.remoteID);+ final sortedFiles = await SearchService.instance.getFilesForPersonID(+ personEntity.remoteID,+ includeManualAssigned: false,+ sortOnTime: true,+ );return FileLoadResult(sortedFiles, false);}diff --git a/mobile/apps/photos/lib/ui/viewer/people/people_page.dart b/mobile/apps/photos/lib/ui/viewer/people/people_page.dartindex b066cf064d..d95678572e 100644--- a/mobile/apps/photos/lib/ui/viewer/people/people_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/people_page.dart@@ -17,7 +17,7 @@ import 'package:photos/models/selected_files.dart';import "package:photos/service_locator.dart";import 'package:photos/services/faces_timeline/faces_timeline_service.dart';import "package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart";-import "package:photos/services/machine_learning/face_ml/person/person_service.dart";+import "package:photos/services/search_service.dart";import "package:photos/ui/components/end_to_end_banner.dart";import 'package:photos/ui/viewer/actions/file_selection_overlay_bar.dart';import 'package:photos/ui/viewer/gallery/gallery.dart';@@ -128,8 +128,10 @@ class _PeoplePageState extends State<PeoplePage> {}Future<List<EnteFile>> _loadPersonFiles() async {- final sortedFiles = await PersonService.instance.loadPersonFiles(+ final sortedFiles = await SearchService.instance.getFilesForPersonID(_person.remoteID,+ includeManualAssigned: true,+ sortOnTime: true,);files = sortedFiles;return sortedFiles;diff --git a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dartindex 60450000fd..1fbea6dd72 100644--- a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart@@ -655,11 +655,10 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {}final List<(PersonEntity, EnteFile, int)> personFileCounts = [];for (final person in persons) {- final clustersToFiles =- await SearchService.instance.getClusterFilesForPersonID(+ final files = await SearchService.instance.getFilesForPersonID(person.remoteID,+ sortOnTime: true,);- final files = clustersToFiles.values.expand((e) => e).toList();if (files.isEmpty) {debugPrint("Person ${kDebugMode ? person.data.name : person.remoteID} has no files",