From ac3f5cd686500c8f39be86402f2656dae6887dbb Mon Sep 17 00:00:00 2001 From: jeacott1 Date: Thu, 5 Jan 2017 00:57:47 +1030 Subject: [PATCH] this function was extremely slow. (#3264) this fix reduces the time to process 165k installations from 282738.599ms (almost 5 minutes of total server lockup!) to just 16.283ms! --- src/StatusHandler.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/StatusHandler.js b/src/StatusHandler.js index 116f4323..e2c0cff4 100644 --- a/src/StatusHandler.js +++ b/src/StatusHandler.js @@ -5,14 +5,15 @@ const PUSH_STATUS_COLLECTION = '_PushStatus'; const JOB_STATUS_COLLECTION = '_JobStatus'; export function flatten(array) { - return array.reduce((memo, element) => { - if (Array.isArray(element)) { - memo = memo.concat(flatten(element)); + var flattened = []; + for(var i = 0; i < array.length; i++) { + if(Array.isArray(array[i])) { + flattened = flattened.concat(flatten(array[i])); } else { - memo = memo.concat(element); + flattened.push(array[i]); } - return memo; - }, []); + } + return flattened; } function statusHandler(className, database) {