From a02876512bbc23997c41f24ed11e2f72569b2604 Mon Sep 17 00:00:00 2001 From: Eemeli Palotie Date: Wed, 8 Nov 2023 18:44:08 +0200 Subject: [PATCH] fix: Analyze commits in batches of 2000 (#86) --- .../src/utils/promise-filter.ts | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/nx-semantic-release/src/utils/promise-filter.ts b/packages/nx-semantic-release/src/utils/promise-filter.ts index 5340d679..7c4b48c0 100644 --- a/packages/nx-semantic-release/src/utils/promise-filter.ts +++ b/packages/nx-semantic-release/src/utils/promise-filter.ts @@ -1,9 +1,21 @@ -export const promiseFilter = ( +export const promiseFilter = async ( array: T[], predicate: (item: T) => Promise -): Promise => - Promise.all( - array.map((item) => - predicate(item).then((result) => (result ? item : null)) - ) - ).then((results) => results.filter(Boolean)) as Promise; +): Promise => { + const chunkSize = 2000; + const chunks = Array(Math.ceil(array.length / chunkSize)) + .fill(null) + .map((_, index) => array.slice(index * chunkSize, (index + 1) * chunkSize)); + + const results = []; + for (const chunk of chunks) { + const chunkResults = await Promise.all( + chunk.map((item) => predicate(item).then((result) => ({ item, result }))) + ); + results.push( + ...chunkResults.filter(({ result }) => result).map(({ item }) => item) + ); + } + + return results; +};