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

This commit is contained in:
laurenspriem 2024-05-20 16:54:22 +05:30
parent 58dcceca9f
commit 3e1e26feb0
4 changed files with 27 additions and 12 deletions

View file

@ -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,
{

View file

@ -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,

View file

@ -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!,
{

View file

@ -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 = [];