Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[face][mob] Log db batch update progress

Neeraj Gupta5b94cbf91271
diff --git a/mobile/lib/face/db.dart b/mobile/lib/face/db.dart
index 0b85e303c6..58a54782a4 100644
--- a/mobile/lib/face/db.dart
+++ b/mobile/lib/face/db.dart
@@ -78,6 +78,37 @@ class FaceMLDataDB {
}
}
+ Future<void> updatePersonIDForFaceIDIFNotSet(
+ Map<String, int> faceIDToPersonID,
+ ) async {
+ final db = await instance.database;
+ const batchSize = 500;
+ final numBatches = (faceIDToPersonID.length / batchSize).ceil();
+
+ for (int i = 0; i < numBatches; i++) {
+ _logger.info('updatePersonIDForFaceIDIFNotSet Batch $i of $numBatches');
+ final start = i * batchSize;
+ final end = min((i + 1) * batchSize, faceIDToPersonID.length);
+ final batch = faceIDToPersonID.entries.toList().sublist(start, end);
+
+ final batchUpdate = db.batch();
+
+ for (final entry in batch) {
+ final faceID = entry.key;
+ final personID = entry.value;
+
+ batchUpdate.update(
+ facesTable,
+ {faceClusterId: personID},
+ where: '$faceIDColumn = ? AND $faceClusterId IS NULL',
+ whereArgs: [faceID],
+ );
+ }
+
+ await batchUpdate.commit(noResult: true);
+ }
+ }
+
Future<Map<int, int>> getIndexedFileIds() async {
final db = await instance.database;
final List<Map<String, dynamic>> maps = await db.rawQuery(
@@ -290,28 +321,6 @@ class FaceMLDataDB {
return result;
}
- Future<void> updatePersonIDForFaceIDIFNotSet(
- Map<String, int> faceIDToPersonID,
- ) async {
- final db = await instance.database;
-
- // Start a batch
- final batch = db.batch();
-
- for (final map in faceIDToPersonID.entries) {
- final faceID = map.key;
- final personID = map.value;
- batch.update(
- facesTable,
- {faceClusterId: personID},
- where: '$faceIDColumn = ? AND $faceClusterId IS NULL',
- whereArgs: [faceID],
- );
- }
- // Commit the batch
- await batch.commit(noResult: true);
- }
-
Future<void> forceUpdateClusterIds(
Map<String, int> faceIDToPersonID,
) async {
@@ -340,7 +349,7 @@ class FaceMLDataDB {
Future<Map<String, (int?, Uint8List)>> getFaceEmbeddingMap({
double minScore = 0.78,
int minClarity = kLaplacianThreshold,
- int maxRows = 20000,
+ int maxRows = 10000,
}) async {
_logger.info('reading as float');
final db = await instance.database;
@@ -370,7 +379,7 @@ class FaceMLDataDB {
result[faceID] =
(map[faceClusterId] as int?, map[faceEmbeddingBlob] as Uint8List);
}
- if (result.length >= 20000) {
+ if (result.length >= maxRows) {
break;
}
offset += batchSize;