From b2a20780458616821ba1a66e457a7b7cfe133f72 Mon Sep 17 00:00:00 2001 From: laurenspriem Date: Thu, 25 Apr 2024 17:06:40 +0530 Subject: [PATCH] [mob][photos] Moving more methods to sqlite async --- mobile/lib/face/db.dart | 34 +++++++++---------- .../face_ml/face_ml_service.dart | 4 +-- .../face_ml/feedback/cluster_feedback.dart | 2 +- .../face_ml/person/person_service.dart | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart index a71fcc886..679a840a6 100644 --- a/mobile/lib/face/db.dart +++ b/mobile/lib/face/db.dart @@ -98,7 +98,7 @@ class FaceMLDataDB { } } - Future updateClusterIdToFaceId( + Future updateFaceIdToClusterId( Map faceIDToClusterID, ) async { final db = await instance.database; @@ -197,8 +197,8 @@ class FaceMLDataDB { int clusterID, { int? limit, }) async { - final db = await instance.database; - final List> maps = await db.rawQuery( + final db = await instance.sqliteAsyncDB; + final List> maps = await db.getAll( 'SELECT $faceEmbeddingBlob FROM $facesTable WHERE $faceIDColumn in (SELECT $fcFaceId from $faceClustersTable where $fcClusterID = ?) ${limit != null ? 'LIMIT $limit' : ''}', [clusterID], ); @@ -209,7 +209,7 @@ class FaceMLDataDB { Iterable clusterIDs, { int? limit, }) async { - final db = await instance.database; + final db = await instance.sqliteAsyncDB; final Map> result = {}; final selectQuery = ''' @@ -220,7 +220,7 @@ class FaceMLDataDB { ${limit != null ? 'LIMIT $limit' : ''} '''; - final List> maps = await db.rawQuery(selectQuery); + final List> maps = await db.getAll(selectQuery); for (final map in maps) { final clusterID = map[fcClusterID] as int; @@ -321,8 +321,8 @@ class FaceMLDataDB { } Future getFaceForFaceID(String faceID) async { - final db = await instance.database; - final result = await db.rawQuery( + final db = await instance.sqliteAsyncDB; + final result = await db.getAll( 'SELECT * FROM $facesTable where $faceIDColumn = ?', [faceID], ); @@ -420,8 +420,8 @@ class FaceMLDataDB { Future> getFaceIdsToClusterIds( Iterable faceIds, ) async { - final db = await instance.database; - final List> maps = await db.rawQuery( + final db = await instance.sqliteAsyncDB; + final List> maps = await db.getAll( 'SELECT $fcFaceId, $fcClusterID FROM $faceClustersTable where $fcFaceId IN (${faceIds.map((id) => "'$id'").join(",")})', ); final Map result = {}; @@ -433,8 +433,8 @@ class FaceMLDataDB { Future>> getFileIdToClusterIds() async { final Map> result = {}; - final db = await instance.database; - final List> maps = await db.rawQuery( + final db = await instance.sqliteAsyncDB; + final List> maps = await db.getAll( 'SELECT $fcClusterID, $fcFaceId FROM $faceClustersTable', ); @@ -791,9 +791,9 @@ class FaceMLDataDB { // for a given personID, return a map of clusterID to fileIDs using join query Future>> getFileIdToClusterIDSet(String personID) { - final db = instance.database; + final db = instance.sqliteAsyncDB; return db.then((db) async { - final List> maps = await db.rawQuery( + final List> maps = await db.getAll( 'SELECT $faceClustersTable.$fcClusterID, $fcFaceId FROM $faceClustersTable ' 'INNER JOIN $clusterPersonTable ' 'ON $faceClustersTable.$fcClusterID = $clusterPersonTable.$clusterIDColumn ' @@ -814,9 +814,9 @@ class FaceMLDataDB { Future>> getFileIdToClusterIDSetForCluster( Set clusterIDs, ) { - final db = instance.database; + final db = instance.sqliteAsyncDB; return db.then((db) async { - final List> maps = await db.rawQuery( + final List> maps = await db.getAll( 'SELECT $fcClusterID, $fcFaceId FROM $faceClustersTable ' 'WHERE $fcClusterID IN (${clusterIDs.join(",")})', ); @@ -894,8 +894,8 @@ class FaceMLDataDB { } Future> getClusterIDToPersonID() async { - final db = await instance.database; - final List> maps = await db.rawQuery( + final db = await instance.sqliteAsyncDB; + final List> maps = await db.getAll( 'SELECT $personIdColumn, $clusterIDColumn FROM $clusterPersonTable', ); final Map result = {}; diff --git a/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart b/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart index da57ad4e7..fbed736e8 100644 --- a/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart +++ b/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart @@ -350,7 +350,7 @@ class FaceMlService { } await FaceMLDataDB.instance - .updateClusterIdToFaceId(clusteringResult.newFaceIdToCluster); + .updateFaceIdToClusterId(clusteringResult.newFaceIdToCluster); await FaceMLDataDB.instance .clusterSummaryUpdate(clusteringResult.newClusterSummaries!); _logger.info( @@ -403,7 +403,7 @@ class FaceMlService { 'Updating ${clusteringResult.newFaceIdToCluster.length} FaceIDs with clusterIDs in the DB', ); await FaceMLDataDB.instance - .updateClusterIdToFaceId(clusteringResult.newFaceIdToCluster); + .updateFaceIdToClusterId(clusteringResult.newFaceIdToCluster); await FaceMLDataDB.instance .clusterSummaryUpdate(clusteringResult.newClusterSummaries!); _logger.info('Done updating FaceIDs with clusterIDs in the DB, in ' diff --git a/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart b/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart index 008559d6d..95b3f2b08 100644 --- a/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart +++ b/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart @@ -412,7 +412,7 @@ class ClusterFeedbackService { final newClusterID = startClusterID + blurValue ~/ 10; faceIdToCluster[faceID] = newClusterID; } - await FaceMLDataDB.instance.updateClusterIdToFaceId(faceIdToCluster); + await FaceMLDataDB.instance.updateFaceIdToClusterId(faceIdToCluster); Bus.instance.fire(PeopleChangedEvent()); } catch (e, s) { 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 da6289953..d860ca4b3 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 @@ -193,7 +193,7 @@ class PersonService { } logger.info("Storing feedback for ${faceIdToClusterID.length} faces"); - await faceMLDataDB.updateClusterIdToFaceId(faceIdToClusterID); + await faceMLDataDB.updateFaceIdToClusterId(faceIdToClusterID); await faceMLDataDB.bulkAssignClusterToPersonID(clusterToPersonID); }