Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Simplify and speed up excluded suggestion cluster queries

laurenspriem657a6e9bbd75
diff --git a/mobile/apps/photos/lib/db/ml/db.dart b/mobile/apps/photos/lib/db/ml/db.dart
index c9480bdaea..45db2d5589 100644
--- a/mobile/apps/photos/lib/db/ml/db.dart
+++ b/mobile/apps/photos/lib/db/ml/db.dart
@@ -513,16 +513,18 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {
GROUP BY fc.$clusterIDColumn
HAVING COUNT(*) = 1
''');
- return rows
- .where(
- (row) => isBadFaceForClustering(
- faceScore: row[faceScore] as double,
- blurValue: row[faceBlur] as double,
- isSideways: (row[isSideways] as int) == 1,
- ),
- )
- .map((row) => row[clusterIDColumn] as String)
- .toSet();
+ final badClusterIDs = <String>{};
+ for (final row in rows) {
+ final badFace = isBadFaceForClustering(
+ faceScore: row[faceScore] as double,
+ blurValue: row[faceBlur] as double,
+ isSideways: (row[isSideways] as int) == 1,
+ );
+ if (badFace) {
+ badClusterIDs.add(row[clusterIDColumn] as String);
+ }
+ }
+ return badClusterIDs;
}
@override
@@ -532,7 +534,7 @@ class MLDataDB with SqlDbBase implements IMLDataDB<int> {
SELECT $clusterIDColumn
FROM $notPersonFeedback
GROUP BY $clusterIDColumn
- HAVING COUNT(DISTINCT $personIdColumn) >= 3
+ HAVING COUNT(*) >= 3
''');
return rows.map((row) => row[clusterIDColumn] as String).toSet();
}
diff --git a/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart b/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
index 83dbd86fb7..73d59d707f 100644
--- a/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
@@ -69,11 +69,11 @@ class ClusterFeedbackService<T> {
}
Future<Set<String>> _getExcludedSuggestionClusterIDs() async {
- final excludedClusterIDs = await mlDataDB.getBadFaceSingletonClusterIDs();
- excludedClusterIDs.addAll(
- await mlDataDB.getClustersWithThreeOrMoreNotPersonFeedback(),
- );
- return excludedClusterIDs;
+ final results = await Future.wait([
+ mlDataDB.getBadFaceSingletonClusterIDs(),
+ mlDataDB.getClustersWithThreeOrMoreNotPersonFeedback(),
+ ]);
+ return results[0].union(results[1]);
}
/// Returns a list of cluster suggestions for a person.