Browse Source

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

laurenspriem 1 year ago
parent
commit
3e1e26feb0

+ 1 - 1
mobile/lib/ui/viewer/file_details/face_widget.dart

@@ -306,7 +306,7 @@ class _FaceWidgetState extends State<FaceWidget> {
         return {widget.face.faceID: data};
         return {widget.face.faceID: data};
       }
       }
 
 
-      final result = await pool.withResource(
+      final result = await poolFullFileFaceGenerations.withResource(
         () async => await getFaceCrops(
         () async => await getFaceCrops(
           widget.file,
           widget.file,
           {
           {

+ 1 - 1
mobile/lib/ui/viewer/file_details/faces_item_widget.dart

@@ -198,7 +198,7 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
         return faceIdToCrop;
         return faceIdToCrop;
       }
       }
 
 
-      final result = await pool.withResource(
+      final result = await poolFullFileFaceGenerations.withResource(
         () async => await getFaceCrops(
         () async => await getFaceCrops(
           widget.file,
           widget.file,
           facesWithoutCrops,
           facesWithoutCrops,

+ 15 - 2
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/ui/viewer/people/cropped_face_image_view.dart";
 import "package:photos/utils/face/face_box_crop.dart";
 import "package:photos/utils/face/face_box_crop.dart";
 import "package:photos/utils/thumbnail_util.dart";
 import "package:photos/utils/thumbnail_util.dart";
+import "package:pool/pool.dart";
 
 
 class PersonFaceWidget extends StatelessWidget {
 class PersonFaceWidget extends StatelessWidget {
   final EnteFile file;
   final EnteFile file;
@@ -155,7 +156,13 @@ class PersonFaceWidget extends StatelessWidget {
         return null;
         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(
         () async => await getFaceCrops(
           fileForFaceCrop!,
           fileForFaceCrop!,
           {
           {
@@ -226,7 +233,13 @@ class PersonFaceWidget extends StatelessWidget {
         return null;
         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(
         () async => await getFaceCrops(
           fileForFaceCrop!,
           fileForFaceCrop!,
           {
           {

+ 10 - 8
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?> faceCropCache = LRUMap(1000);
 final LRUMap<String, Uint8List?> faceCropThumbnailCache = 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(
 Future<Map<String, Uint8List>?> getFaceCrops(
   EnteFile file,
   EnteFile file,
   Map<String, FaceBox> faceBoxeMap, {
   Map<String, FaceBox> faceBoxeMap, {
   bool useFullFile = true,
   bool useFullFile = true,
-  }
-) async {
+}) async {
   late String? imagePath;
   late String? imagePath;
   if (useFullFile && file.fileType != FileType.video) {
   if (useFullFile && file.fileType != FileType.video) {
     final File? ioFile = await getFile(file);
     final File? ioFile = await getFile(file);
@@ -28,11 +30,11 @@ Future<Map<String, Uint8List>?> getFaceCrops(
     }
     }
     imagePath = ioFile.path;
     imagePath = ioFile.path;
   } else {
   } 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<String> faceIds = [];
   final List<FaceBox> faceBoxes = [];
   final List<FaceBox> faceBoxes = [];