diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart index 03c4fc54c..2eb2ef02d 100644 --- a/mobile/lib/face/db.dart +++ b/mobile/lib/face/db.dart @@ -130,18 +130,12 @@ class FaceMLDataDB { /// Returns a map of fileID to the indexed ML version Future> getIndexedFileIds({int? minimumMlVersion}) async { final db = await instance.asyncDB; - late final String query; + String query = ''' + SELECT $fileIDColumn, $mlVersionColumn + FROM $facesTable + '''; if (minimumMlVersion != null) { - query = ''' - SELECT $fileIDColumn, $mlVersionColumn - FROM $facesTable - WHERE $mlVersionColumn >= $minimumMlVersion - '''; - } else { - query = ''' - SELECT $fileIDColumn, $mlVersionColumn - FROM $facesTable - '''; + query += ' WHERE $mlVersionColumn >= $minimumMlVersion'; } final List> maps = await db.getAll(query); final Map result = {}; @@ -151,11 +145,14 @@ class FaceMLDataDB { return result; } - Future getIndexedFileCount() async { + Future getIndexedFileCount({int? minimumMlVersion}) async { final db = await instance.asyncDB; - final List> maps = await db.getAll( - 'SELECT COUNT(DISTINCT $fileIDColumn) as count FROM $facesTable', - ); + String query = + 'SELECT COUNT(DISTINCT $fileIDColumn) as count FROM $facesTable'; + if (minimumMlVersion != null) { + query += ' WHERE $mlVersionColumn >= $minimumMlVersion'; + } + final List> maps = await db.getAll(query); return maps.first['count'] as int; } 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 2fd9fd8fd..d642b6363 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 @@ -1424,9 +1424,8 @@ class FaceMlService { indexableFiles.add(enteFile); } - final Map alreadyIndexedFiles = await FaceMLDataDB.instance - .getIndexedFileIds(minimumMlVersion: faceMlVersion); - final int alreadyIndexedCount = alreadyIndexedFiles.length; + final int alreadyIndexedCount = await FaceMLDataDB.instance + .getIndexedFileCount(minimumMlVersion: faceMlVersion); final int totalIndexableCount = indexableFiles.length; final ratio = alreadyIndexedCount / totalIndexableCount; w?.log('getIndexedDoneRatio');