From e6789dd02a3d076afed1840013b9846177acae28 Mon Sep 17 00:00:00 2001 From: Alex Brohshtut Date: Mon, 15 Aug 2022 18:02:16 +0300 Subject: [PATCH] Improve performance by replacing reduce with spread with forEach --- src/consumer/consumerGroup.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/consumer/consumerGroup.js b/src/consumer/consumerGroup.js index 4b9067695..442312c1a 100644 --- a/src/consumer/consumerGroup.js +++ b/src/consumer/consumerGroup.js @@ -747,8 +747,13 @@ module.exports = class ConsumerGroup { } getActiveTopicPartitions() { - return this.subscriptionState - .active() - .reduce((acc, { topic, partitions }) => ({ ...acc, [topic]: new Set(partitions) }), {}) + const activeSubscriptionState = this.subscriptionState.active() + + const activeTopicPartitions = {} + activeSubscriptionState.forEach(({ topic, partitions }) => { + activeTopicPartitions[topic] = new Set(partitions) + }) + + return activeTopicPartitions } }