From 7e9c6a7f81169e4af9f71e4201fe7b566a8c509f Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Mon, 1 Apr 2024 15:44:25 +0530 Subject: [PATCH] [mob] Rename --- mobile/lib/face/db.dart | 57 +++++++------------ mobile/lib/face/db_fields.dart | 6 +- .../debug/face_debug_section_widget.dart | 9 +-- .../people/add_person_action_sheet.dart | 6 +- 4 files changed, 32 insertions(+), 46 deletions(-) diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart index 84a208f04..cf0678ecc 100644 --- a/mobile/lib/face/db.dart +++ b/mobile/lib/face/db.dart @@ -18,7 +18,7 @@ import 'package:sqflite/sqflite.dart'; /// /// This includes: /// [facesTable] - Stores all the detected faces and its embeddings in the images. -/// [peopleTable] - Stores all the clusters of faces which are considered to be the same person. +/// [personTable] - Stores all the clusters of faces which are considered to be the same person. class FaceMLDataDB { static final Logger _logger = Logger("FaceMLDataDB"); @@ -49,7 +49,7 @@ class FaceMLDataDB { Future _onCreate(Database db, int version) async { await db.execute(createFacesTable); - await db.execute(createPeopleTable); + await db.execute(createPersonTable); await db.execute(createClusterTable); await db.execute(createClusterSummaryTable); await db.execute(createNotPersonFeedbackTable); @@ -165,7 +165,7 @@ class FaceMLDataDB { await db.delete(facesTable); await db.delete(clustersTable); await db.delete(clusterSummaryTable); - await db.delete(peopleTable); + await db.delete(personTable); await db.delete(notPersonFeedback); } @@ -203,7 +203,7 @@ class FaceMLDataDB { final db = await instance.database; if (personID != null) { final List> maps = await db.rawQuery( - 'SELECT * FROM $peopleTable where $idColumn = ?', + 'SELECT * FROM $personTable where $idColumn = ?', [personID], ); if (maps.isEmpty) { @@ -450,7 +450,7 @@ class FaceMLDataDB { debugPrint("inserting person"); final db = await instance.database; await db.insert( - peopleTable, + personTable, mapPersonToRow(p), conflictAlgorithm: ConflictAlgorithm.replace, ); @@ -467,7 +467,7 @@ class FaceMLDataDB { Future updatePerson(Person p) async { final db = await instance.database; await db.update( - peopleTable, + personTable, mapPersonToRow(p), where: '$idColumn = ?', whereArgs: [p.remoteID], @@ -597,14 +597,18 @@ class FaceMLDataDB { Future<(Map, Map)> getClusterIdToPerson() async { final db = await instance.database; - final Map peopleMap = await getPeopleMap(); + final List persons = await getPersons(); + final Map personMap = {}; + for (final p in persons) { + personMap[p.remoteID] = p; + } final List> maps = await db.rawQuery( 'SELECT $personIdColumn, $cluserIDColumn FROM $clustersTable', ); final Map result = {}; for (final map in maps) { - final Person? p = peopleMap[map[personIdColumn] as String]; + final Person? p = personMap[map[personIdColumn] as String]; if (p != null) { result[map[cluserIDColumn] as int] = p; } else { @@ -613,32 +617,13 @@ class FaceMLDataDB { ); } } - return (result, peopleMap); + return (result, personMap); } - Future> getPeopleMap() async { + Future> getPersons() async { final db = await instance.database; final List> maps = await db.query( - peopleTable, - columns: [ - idColumn, - nameColumn, - personHiddenColumn, - clusterToFaceIdJson, - coverFaceIDColumn, - ], - ); - final Map result = {}; - for (final map in maps) { - result[map[idColumn] as String] = mapRowToPerson(map); - } - return result; - } - - Future> getPeople() async { - final db = await instance.database; - final List> maps = await db.query( - peopleTable, + personTable, columns: [ idColumn, nameColumn, @@ -651,33 +636,33 @@ class FaceMLDataDB { } /// WARNING: This will delete ALL data in the database! Only use this for debug/testing purposes! - Future dropClustersAndPeople({bool faces = false}) async { + Future dropClustersAndPersonTable({bool faces = false}) async { final db = await instance.database; if (faces) { await db.execute(deleteFacesTable); await db.execute(createFacesTable); } - await db.execute(deletePeopleTable); + await db.execute(deletePersonTable); await db.execute(dropClustersTable); await db.execute(dropClusterSummaryTable); await db.execute(dropNotPersonFeedbackTable); - await db.execute(createPeopleTable); + await db.execute(createPersonTable); await db.execute(createClusterTable); await db.execute(createNotPersonFeedbackTable); await db.execute(createClusterSummaryTable); } /// WARNING: This will delete ALL data in the database! Only use this for debug/testing purposes! - Future dropPeople() async { + Future dropPersonTable() async { final db = await instance.database; - await db.execute(deletePeopleTable); + await db.execute(deletePersonTable); await db.execute(dropClustersTable); await db.execute(dropNotPersonFeedbackTable); // await db.execute(createFacesTable); - await db.execute(createPeopleTable); + await db.execute(createPersonTable); await db.execute(createClusterTable); await db.execute(createNotPersonFeedbackTable); } diff --git a/mobile/lib/face/db_fields.dart b/mobile/lib/face/db_fields.dart index e43747f68..303c298b1 100644 --- a/mobile/lib/face/db_fields.dart +++ b/mobile/lib/face/db_fields.dart @@ -34,14 +34,14 @@ const deleteFacesTable = 'DROP TABLE IF EXISTS $facesTable'; // End of Faces Table Fields & Schema Queries // People Table Fields & Schema Queries -const peopleTable = 'people'; +const personTable = 'people'; const idColumn = 'id'; const nameColumn = 'name'; const personHiddenColumn = 'hidden'; const clusterToFaceIdJson = 'clusterToFaceIds'; const coverFaceIDColumn = 'cover_face_id'; -const createPeopleTable = '''CREATE TABLE IF NOT EXISTS $peopleTable ( +const createPersonTable = '''CREATE TABLE IF NOT EXISTS $personTable ( $idColumn TEXT NOT NULL UNIQUE, $nameColumn TEXT NOT NULL DEFAULT '', $personHiddenColumn INTEGER NOT NULL DEFAULT 0, @@ -51,7 +51,7 @@ const createPeopleTable = '''CREATE TABLE IF NOT EXISTS $peopleTable ( ); '''; -const deletePeopleTable = 'DROP TABLE IF EXISTS $peopleTable'; +const deletePersonTable = 'DROP TABLE IF EXISTS $personTable'; //End People Table Fields & Schema Queries // Clusters Table Fields & Schema Queries diff --git a/mobile/lib/ui/settings/debug/face_debug_section_widget.dart b/mobile/lib/ui/settings/debug/face_debug_section_widget.dart index ae549b673..ee30db686 100644 --- a/mobile/lib/ui/settings/debug/face_debug_section_widget.dart +++ b/mobile/lib/ui/settings/debug/face_debug_section_widget.dart @@ -173,7 +173,7 @@ class _FaceDebugSectionWidgetState extends State { trailingIcon: Icons.chevron_right_outlined, trailingIconIsMuted: true, onTap: () async { - await FaceMLDataDB.instance.dropPeople(); + await FaceMLDataDB.instance.dropPersonTable(); Bus.instance.fire(PeopleChangedEvent()); showShortToast(context, "Done"); }, @@ -195,7 +195,7 @@ class _FaceDebugSectionWidgetState extends State { firstButtonLabel: "Yes, confirm", firstButtonOnTap: () async { await FaceMLDataDB.instance.resetClusterIDs(); - await FaceMLDataDB.instance.dropClustersAndPeople(); + await FaceMLDataDB.instance.dropClustersAndPersonTable(); Bus.instance.fire(PeopleChangedEvent()); showShortToast(context, "Done"); }, @@ -218,7 +218,8 @@ class _FaceDebugSectionWidgetState extends State { "You will need to again re-index all the faces. You can drop feedback if you want to label again", firstButtonLabel: "Yes, confirm", firstButtonOnTap: () async { - await FaceMLDataDB.instance.dropClustersAndPeople(faces: true); + await FaceMLDataDB.instance + .dropClustersAndPersonTable(faces: true); Bus.instance.fire(PeopleChangedEvent()); showShortToast(context, "Done"); }, @@ -237,7 +238,7 @@ class _FaceDebugSectionWidgetState extends State { onTap: () async { try { final List persons = - await FaceMLDataDB.instance.getPeople(); + await FaceMLDataDB.instance.getPersons(); final EnteWatch w = EnteWatch('feedback')..start(); for (final Person p in persons) { await ClusterFeedbackService.instance diff --git a/mobile/lib/ui/viewer/people/add_person_action_sheet.dart b/mobile/lib/ui/viewer/people/add_person_action_sheet.dart index 935af9880..dbf8dda73 100644 --- a/mobile/lib/ui/viewer/people/add_person_action_sheet.dart +++ b/mobile/lib/ui/viewer/people/add_person_action_sheet.dart @@ -275,8 +275,8 @@ class _PersonActionSheetState extends State { PersonAttr(name: text, faces: []), ); await FaceMLDataDB.instance.insert(p, clusterID); - final bool extraPhotosFound = - await ClusterFeedbackService.instance.checkAndDoAutomaticMerges(p); + final bool extraPhotosFound = await ClusterFeedbackService.instance + .checkAndDoAutomaticMerges(p); if (extraPhotosFound) { showShortToast(context, "Extra photos found for $text"); } @@ -296,6 +296,6 @@ class _PersonActionSheetState extends State { } Future> _getPersons() async { - return FaceMLDataDB.instance.getPeople(); + return FaceMLDataDB.instance.getPersons(); } }