Skip to content

Commit fa724d8

Browse files
committed
feat: improve perf of groupMessagesForPartition
1 parent ff3b111 commit fa724d8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/producer/groupMessagesPerPartition.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ module.exports = ({ topic, partitionMetadata, messages, partitioner }) => {
33
return {}
44
}
55

6-
return messages.reduce((result, message) => {
6+
const grouping = {}
7+
for (const message of messages) {
78
const partition = partitioner({ topic, partitionMetadata, message })
8-
const current = result[partition] || []
9-
return Object.assign(result, { [partition]: [...current, message] })
10-
}, {})
9+
if (grouping[partition] === undefined) {
10+
grouping[partition] = []
11+
}
12+
grouping[partition].push(message)
13+
}
14+
15+
return grouping
1116
}

0 commit comments

Comments
 (0)