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!
This commit is contained in:
jeacott1
2017-01-05 00:57:47 +10:30
committed by Florent Vilmart
parent 9fd34fd25e
commit ac3f5cd686

View File

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