mirror of
https://github.com/ente-io/ente.git
synced 2025-08-08 07:28:26 +00:00
[mob][photos] Fix face thumbnail generation pool issue
This commit is contained in:
parent
8975af7a71
commit
853f291de3
@ -293,7 +293,7 @@ class _FaceWidgetState extends State<FaceWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, Uint8List>?> getFaceCrop() async {
|
||||
Future<Map<String, Uint8List>?> getFaceCrop({int fetchAttempt = 1}) async {
|
||||
try {
|
||||
final Uint8List? cachedFace = faceCropCache.get(widget.face.faceID);
|
||||
if (cachedFace != null) {
|
||||
@ -326,6 +326,10 @@ class _FaceWidgetState extends State<FaceWidget> {
|
||||
error: e,
|
||||
stackTrace: s,
|
||||
);
|
||||
resetPool(fullFile: true);
|
||||
if (fetchAttempt <= retryLimit) {
|
||||
return getFaceCrop(fetchAttempt: fetchAttempt + 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +173,9 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
|
||||
}
|
||||
|
||||
Future<Map<String, Uint8List>?> getRelevantFaceCrops(
|
||||
Iterable<Face> faces,
|
||||
Iterable<Face> faces, {
|
||||
int fetchAttempt = 1,
|
||||
}
|
||||
) async {
|
||||
try {
|
||||
final faceIdToCrop = <String, Uint8List>{};
|
||||
@ -223,6 +225,10 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
|
||||
error: e,
|
||||
stackTrace: s,
|
||||
);
|
||||
resetPool(fullFile: true);
|
||||
if(fetchAttempt <= retryLimit) {
|
||||
return getRelevantFaceCrops(faces, fetchAttempt: fetchAttempt + 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ class PersonFaceWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Future<Uint8List?> getFaceCrop() async {
|
||||
Future<Uint8List?> getFaceCrop({int fetchAttempt = 1}) async {
|
||||
try {
|
||||
final Face? face = await _getFace();
|
||||
if (face == null) {
|
||||
@ -187,6 +187,10 @@ class PersonFaceWidget extends StatelessWidget {
|
||||
error: e,
|
||||
stackTrace: s,
|
||||
);
|
||||
resetPool(fullFile: useFullFile);
|
||||
if(fetchAttempt <= retryLimit) {
|
||||
return getFaceCrop(fetchAttempt: fetchAttempt + 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,20 @@ import "package:photos/utils/image_ml_isolate.dart";
|
||||
import "package:photos/utils/thumbnail_util.dart";
|
||||
import "package:pool/pool.dart";
|
||||
|
||||
void resetPool({required bool fullFile}) {
|
||||
if (fullFile) {
|
||||
poolFullFileFaceGenerations = Pool(20, timeout: const Duration(seconds: 15));
|
||||
} else {
|
||||
poolThumbnailFaceGenerations = Pool(100, timeout: const Duration(seconds: 15));
|
||||
}
|
||||
}
|
||||
|
||||
const int retryLimit = 3;
|
||||
final LRUMap<String, Uint8List?> faceCropCache = LRUMap(1000);
|
||||
final LRUMap<String, Uint8List?> faceCropThumbnailCache = LRUMap(1000);
|
||||
final poolFullFileFaceGenerations =
|
||||
Pool poolFullFileFaceGenerations =
|
||||
Pool(20, timeout: const Duration(seconds: 15));
|
||||
final poolThumbnailFaceGenerations =
|
||||
Pool poolThumbnailFaceGenerations =
|
||||
Pool(100, timeout: const Duration(seconds: 15));
|
||||
Future<Map<String, Uint8List>?> getFaceCrops(
|
||||
EnteFile file,
|
||||
|
Loading…
x
Reference in New Issue
Block a user