From 3b8cae068ecaffe0fdc5d4baf3a3b83afc26cf3e Mon Sep 17 00:00:00 2001 From: laurenspriem Date: Tue, 14 May 2024 12:03:15 +0530 Subject: [PATCH] [mob][photos] Retries for fetching face embeddings --- .../machine_learning/face_ml/face_ml_service.dart | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart b/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart index 5d592d5793..e4282a0ebe 100644 --- a/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart +++ b/mobile/lib/services/machine_learning/face_ml/face_ml_service.dart @@ -484,7 +484,7 @@ class FaceMlService { /// Analyzes all the images in the database with the latest ml version and stores the results in the database. /// /// This function first checks if the image has already been analyzed with the lastest faceMlVersion and stored in the database. If so, it skips the image. - Future indexAllImages() async { + Future indexAllImages({int retryFetchCount = 10}) async { if (isImageIndexRunning) { _logger.warning("indexAllImages is already running, skipping"); return; @@ -589,7 +589,18 @@ class FaceMlService { .info('already indexed files ${remoteFileIdToVersion.length}'); } catch (e, s) { _logger.severe("err while getting files embeddings", e, s); - rethrow; + if (retryFetchCount < 1000) { + Future.delayed(Duration(seconds: retryFetchCount), () { + unawaited(indexAllImages(retryFetchCount: retryFetchCount * 2)); + }); + return; + } else { + _logger.severe( + "Failed to fetch embeddings for files after multiple retries", + e, + s,); + rethrow; + } } } final smallerChunks = chunk.chunks(_parallelism);