[mob] Remove personEntity dependency from faceDB
This commit is contained in:
parent
199dad3705
commit
2456c02956
4 changed files with 19 additions and 27 deletions
|
@ -9,7 +9,6 @@ import 'package:path_provider/path_provider.dart';
|
|||
import 'package:photos/face/db_fields.dart';
|
||||
import "package:photos/face/db_model_mappers.dart";
|
||||
import "package:photos/face/model/face.dart";
|
||||
import "package:photos/face/model/person.dart";
|
||||
import "package:photos/models/file/file.dart";
|
||||
import 'package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
@ -49,10 +48,10 @@ class FaceMLDataDB {
|
|||
|
||||
Future _onCreate(Database db, int version) async {
|
||||
await db.execute(createFacesTable);
|
||||
await db.execute(createFaceClustersTable);
|
||||
await db.execute(createClusterPersonTable);
|
||||
await db.execute(createClusterSummaryTable);
|
||||
await db.execute(createNotPersonFeedbackTable);
|
||||
await db.execute(createFaceClustersTable);
|
||||
await db.execute(fcClusterIDIndex);
|
||||
}
|
||||
|
||||
|
@ -416,7 +415,7 @@ class FaceMLDataDB {
|
|||
Future<Map<String, Uint8List>> getFaceEmbeddingMapForFile(
|
||||
List<int> fileIDs,
|
||||
) async {
|
||||
_logger.info('reading as float');
|
||||
_logger.info('reading face embeddings for ${fileIDs.length} files');
|
||||
final db = await instance.database;
|
||||
|
||||
// Define the batch size
|
||||
|
@ -448,6 +447,7 @@ class FaceMLDataDB {
|
|||
}
|
||||
offset += batchSize;
|
||||
}
|
||||
_logger.info('done reading face embeddings for ${fileIDs.length} files');
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -591,24 +591,14 @@ class FaceMLDataDB {
|
|||
return result;
|
||||
}
|
||||
|
||||
Future<Map<int, PersonEntity>> getClusterIdToPerson(
|
||||
Map<String, PersonEntity> personMap,
|
||||
) async {
|
||||
Future<Map<int, String>> getClusterIDToPersonID() async {
|
||||
final db = await instance.database;
|
||||
final List<Map<String, dynamic>> maps = await db.rawQuery(
|
||||
'SELECT $personIdColumn, $cluserIDColumn FROM $clusterPersonTable',
|
||||
);
|
||||
|
||||
final Map<int, PersonEntity> result = {};
|
||||
final Map<int, String> result = {};
|
||||
for (final map in maps) {
|
||||
final PersonEntity? p = personMap[map[personIdColumn] as String];
|
||||
if (p != null) {
|
||||
result[map[cluserIDColumn] as int] = p;
|
||||
} else {
|
||||
_logger.warning(
|
||||
'Person with id ${map[personIdColumn]} not found',
|
||||
);
|
||||
}
|
||||
result[map[cluserIDColumn] as int] = map[personIdColumn] as String;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -648,14 +638,14 @@ class FaceMLDataDB {
|
|||
|
||||
Future<void> removeFilesFromPerson(
|
||||
List<EnteFile> files,
|
||||
PersonEntity p,
|
||||
String personID,
|
||||
) async {
|
||||
final db = await instance.database;
|
||||
final faceIdsResult = await db.rawQuery(
|
||||
'SELECT $fcFaceId FROM $faceClustersTable LEFT JOIN $clusterPersonTable '
|
||||
'ON $faceClustersTable.$fcClusterID = $clusterPersonTable.$cluserIDColumn '
|
||||
'WHERE $clusterPersonTable.$personIdColumn = ?',
|
||||
[p.remoteID],
|
||||
[personID],
|
||||
);
|
||||
final Set<String> fileIds = {};
|
||||
for (final enteFile in files) {
|
||||
|
|
|
@ -326,7 +326,7 @@ class ClusterFeedbackService {
|
|||
}
|
||||
|
||||
Future<void> removeFilesFromPerson(List<EnteFile> files, PersonEntity p) {
|
||||
return FaceMLDataDB.instance.removeFilesFromPerson(files, p);
|
||||
return FaceMLDataDB.instance.removeFilesFromPerson(files, p.remoteID);
|
||||
}
|
||||
|
||||
Future<void> removeFilesFromCluster(List<EnteFile> files, int clusterID) {
|
||||
|
|
|
@ -742,8 +742,8 @@ class SearchService {
|
|||
await FaceMLDataDB.instance.getFileIdToClusterIds();
|
||||
final Map<String, PersonEntity> personIdToPerson =
|
||||
await PersonService.instance.getPersonsMap();
|
||||
final clusterIDToPerson =
|
||||
await FaceMLDataDB.instance.getClusterIdToPerson(personIdToPerson);
|
||||
final clusterIDToPersonID =
|
||||
await FaceMLDataDB.instance.getClusterIDToPersonID();
|
||||
|
||||
final List<GenericSearchResult> facesResult = [];
|
||||
final Map<int, List<EnteFile>> clusterIdToFiles = {};
|
||||
|
@ -755,7 +755,7 @@ class SearchService {
|
|||
}
|
||||
final cluserIds = fileIdToClusterID[f.uploadedFileID ?? -1]!;
|
||||
for (final cluster in cluserIds) {
|
||||
final PersonEntity? p = clusterIDToPerson[cluster];
|
||||
final PersonEntity? p = personIdToPerson[clusterIDToPersonID[cluster] ?? ""];
|
||||
if (p != null) {
|
||||
if (personIdToFiles.containsKey(p.remoteID)) {
|
||||
personIdToFiles[p.remoteID]!.add(f);
|
||||
|
@ -815,9 +815,9 @@ class SearchService {
|
|||
final files = clusterIdToFiles[clusterId]!;
|
||||
// final String clusterName = "ID:$clusterId, ${files.length}";
|
||||
final String clusterName = "${files.length}";
|
||||
final PersonEntity? p = clusterIDToPerson[clusterId];
|
||||
if (p != null) {
|
||||
throw Exception("Person should be null");
|
||||
|
||||
if (clusterIDToPersonID[clusterId] != null) {
|
||||
throw Exception("Cluster $clusterId should not have person id ${clusterIDToPersonID[clusterId]}");
|
||||
}
|
||||
if (files.length < 3) {
|
||||
continue;
|
||||
|
|
|
@ -70,14 +70,16 @@ class FacesItemWidget extends StatelessWidget {
|
|||
final Map<String, PersonEntity> persons =
|
||||
await PersonService.instance.getPersonsMap();
|
||||
final clusterIDToPerson =
|
||||
await FaceMLDataDB.instance.getClusterIdToPerson(persons);
|
||||
await FaceMLDataDB.instance.getClusterIDToPersonID();
|
||||
|
||||
final lastViewedClusterID = ClusterFeedbackService.lastViewedClusterID;
|
||||
|
||||
final faceWidgets = <FaceWidget>[];
|
||||
for (final Face face in faces) {
|
||||
final int? clusterID = faceIdsToClusterIds[face.faceID];
|
||||
final PersonEntity? person = clusterIDToPerson[clusterID];
|
||||
final PersonEntity? person = clusterIDToPerson[clusterID] != null
|
||||
? persons[clusterIDToPerson[clusterID]!]
|
||||
: null;
|
||||
final highlight =
|
||||
(clusterID == lastViewedClusterID) && (person == null);
|
||||
faceWidgets.add(
|
||||
|
|
Loading…
Add table
Reference in a new issue