Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Bigger and separate resources pool for face generation

laurenspriem3e1e26feb0d3
diff --git a/mobile/lib/ui/viewer/file_details/face_widget.dart b/mobile/lib/ui/viewer/file_details/face_widget.dart
index 2fcc39de96..1ec7a2eb2d 100644
--- a/mobile/lib/ui/viewer/file_details/face_widget.dart
+++ b/mobile/lib/ui/viewer/file_details/face_widget.dart
@@ -306,7 +306,7 @@ class _FaceWidgetState extends State<FaceWidget> {
return {widget.face.faceID: data};
}
- final result = await pool.withResource(
+ final result = await poolFullFileFaceGenerations.withResource(
() async => await getFaceCrops(
widget.file,
{
diff --git a/mobile/lib/ui/viewer/file_details/faces_item_widget.dart b/mobile/lib/ui/viewer/file_details/faces_item_widget.dart
index 572312c925..0e31960fda 100644
--- a/mobile/lib/ui/viewer/file_details/faces_item_widget.dart
+++ b/mobile/lib/ui/viewer/file_details/faces_item_widget.dart
@@ -198,7 +198,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
return faceIdToCrop;
}
- final result = await pool.withResource(
+ final result = await poolFullFileFaceGenerations.withResource(
() async => await getFaceCrops(
widget.file,
facesWithoutCrops,
diff --git a/mobile/lib/ui/viewer/search/result/person_face_widget.dart b/mobile/lib/ui/viewer/search/result/person_face_widget.dart
index 6b4c922ce3..8be99e5f6e 100644
--- a/mobile/lib/ui/viewer/search/result/person_face_widget.dart
+++ b/mobile/lib/ui/viewer/search/result/person_face_widget.dart
@@ -15,6 +15,7 @@ import "package:photos/ui/viewer/file_details/face_widget.dart";
import "package:photos/ui/viewer/people/cropped_face_image_view.dart";
import "package:photos/utils/face/face_box_crop.dart";
import "package:photos/utils/thumbnail_util.dart";
+import "package:pool/pool.dart";
class PersonFaceWidget extends StatelessWidget {
final EnteFile file;
@@ -155,7 +156,13 @@ class PersonFaceWidget extends StatelessWidget {
return null;
}
- final result = await pool.withResource(
+ late final Pool relevantResourcePool;
+ if (useFullFile) {
+ relevantResourcePool = poolFullFileFaceGenerations;
+ } else {
+ relevantResourcePool = poolThumbnailFaceGenerations;
+ }
+ final result = await relevantResourcePool.withResource(
() async => await getFaceCrops(
fileForFaceCrop!,
{
@@ -226,7 +233,13 @@ class PersonFaceWidget extends StatelessWidget {
return null;
}
- final result = await pool.withResource(
+ late final Pool relevantResourcePool;
+ if (useFullFile) {
+ relevantResourcePool = poolFullFileFaceGenerations;
+ } else {
+ relevantResourcePool = poolThumbnailFaceGenerations;
+ }
+ final result = await relevantResourcePool.withResource(
() async => await getFaceCrops(
fileForFaceCrop!,
{
diff --git a/mobile/lib/utils/face/face_box_crop.dart b/mobile/lib/utils/face/face_box_crop.dart
index a59bd53263..281c0ef495 100644
--- a/mobile/lib/utils/face/face_box_crop.dart
+++ b/mobile/lib/utils/face/face_box_crop.dart
@@ -13,13 +13,15 @@ import "package:pool/pool.dart";
final LRUMap<String, Uint8List?> faceCropCache = LRUMap(1000);
final LRUMap<String, Uint8List?> faceCropThumbnailCache = LRUMap(1000);
-final pool = Pool(10, timeout: const Duration(seconds: 15));
+final poolFullFileFaceGenerations =
+ Pool(20, timeout: const Duration(seconds: 15));
+final poolThumbnailFaceGenerations =
+ Pool(100, timeout: const Duration(seconds: 15));
Future<Map<String, Uint8List>?> getFaceCrops(
EnteFile file,
Map<String, FaceBox> faceBoxeMap, {
bool useFullFile = true,
- }
-) async {
+}) async {
late String? imagePath;
if (useFullFile && file.fileType != FileType.video) {
final File? ioFile = await getFile(file);
@@ -28,11 +30,11 @@ Future<Map<String, Uint8List>?> getFaceCrops(
}
imagePath = ioFile.path;
} else {
- final thumbnail = await getThumbnailForUploadedFile(file);
- if (thumbnail == null) {
- return null;
- }
- imagePath = thumbnail.path;
+ final thumbnail = await getThumbnailForUploadedFile(file);
+ if (thumbnail == null) {
+ return null;
+ }
+ imagePath = thumbnail.path;
}
final List<String> faceIds = [];
final List<FaceBox> faceBoxes = [];