From 387f13a5623aee932519114bc9ecd87cdc0826e4 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 11 Apr 2022 14:02:04 +0530 Subject: [PATCH] run face object and text detection parallely --- .../machineLearning/machineLearningService.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/services/machineLearning/machineLearningService.ts b/src/services/machineLearning/machineLearningService.ts index 5b12adc15..132daab61 100644 --- a/src/services/machineLearning/machineLearningService.ts +++ b/src/services/machineLearning/machineLearningService.ts @@ -402,7 +402,8 @@ class MachineLearningService { } else if (fileContext.oldMlFile?.mlVersion) { newMlFile.mlVersion = fileContext.oldMlFile.mlVersion; } - try { + + const faceDetection = async () => { await FaceService.syncFileFaceDetections(syncContext, fileContext); if (newMlFile.faces && newMlFile.faces.length > 0) { @@ -418,16 +419,16 @@ class MachineLearningService { fileContext ); } - - await ObjectService.syncFileObjectDetections( - syncContext, - fileContext - ); - - await promiseWithTimeout( + }; + try { + await Promise.all([ + faceDetection(), + ObjectService.syncFileObjectDetections( + syncContext, + fileContext + ), TextService.syncFileTextDetections(syncContext, fileContext), - ML_DETECTION_TIMEOUT_MS - ); + ]); } catch (e) { newMlFile.mlVersion = oldMlFile.mlVersion; throw e;