Skip to content

Commit ac3f5cd

Browse files
jeacott1flovilmart
jeacott1
authored andcommitted
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!
1 parent 9fd34fd commit ac3f5cd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/StatusHandler.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ const PUSH_STATUS_COLLECTION = '_PushStatus';
55
const JOB_STATUS_COLLECTION = '_JobStatus';
66

77
export function flatten(array) {
8-
return array.reduce((memo, element) => {
9-
if (Array.isArray(element)) {
10-
memo = memo.concat(flatten(element));
8+
var flattened = [];
9+
for(var i = 0; i < array.length; i++) {
10+
if(Array.isArray(array[i])) {
11+
flattened = flattened.concat(flatten(array[i]));
1112
} else {
12-
memo = memo.concat(element);
13+
flattened.push(array[i]);
1314
}
14-
return memo;
15-
}, []);
15+
}
16+
return flattened;
1617
}
1718

1819
function statusHandler(className, database) {

0 commit comments

Comments
 (0)