[mob][photos] Show smaller people clusters for small libraries

This commit is contained in:
laurenspriem
2024-10-17 10:31:32 +05:30
parent 7df6872579
commit f2849b3daf
3 changed files with 24 additions and 7 deletions

View File

@@ -18,3 +18,6 @@ const kMinFaceDetectionScore = FaceDetectionService.kMinScoreSigmoidThreshold;
/// The minimum cluster size for displaying a cluster in the UI
const kMinimumClusterSizeSearchResult = 10;
/// The minimum cluster sizes to try when the normal minimum doesn't return any results
const kLowerMinimumClusterSizes = [5, 3, 2, 1];

View File

@@ -765,7 +765,10 @@ class SearchService {
return clusterIDToFiles;
}
Future<List<GenericSearchResult>> getAllFace(int? limit) async {
Future<List<GenericSearchResult>> getAllFace(
int? limit, {
int minClusterSize = kMinimumClusterSizeSearchResult,
}) async {
try {
debugPrint("getting faces");
final Map<int, Set<String>> fileIdToClusterID =
@@ -857,10 +860,7 @@ class SearchService {
"`getAllFace`: Cluster $clusterId should not have person id ${clusterIDToPersonID[clusterId]}",
);
}
if (files.length < kMinimumClusterSizeSearchResult &&
sortedClusterIds.length > 3) {
continue;
}
if (files.length < minClusterSize) continue;
facesResult.add(
GenericSearchResult(
ResultType.faces,
@@ -883,6 +883,20 @@ class SearchService {
),
);
}
if (facesResult.isEmpty) {
int newMinimum = minClusterSize;
for (final int minimum in kLowerMinimumClusterSizes) {
if (minimum < minClusterSize) {
newMinimum = minimum;
break;
}
}
if (newMinimum < minClusterSize) {
return getAllFace(limit, minClusterSize: newMinimum);
} else {
return [];
}
}
if (limit != null) {
return facesResult.sublist(0, min(limit, facesResult.length));
} else {

View File

@@ -30,10 +30,10 @@ class PeopleSection extends StatefulWidget {
final int limit;
const PeopleSection({
Key? key,
super.key,
required this.examples,
this.limit = 7,
}) : super(key: key);
});
@override
State<PeopleSection> createState() => _PeopleSectionState();