Skip to content

Commit

Permalink
Merge pull request #1 from benvan/master
Browse files Browse the repository at this point in the history
feat: improve perf of groupMessagesForPartition
  • Loading branch information
terebentina authored Jun 9, 2023
2 parents ff3b111 + fa724d8 commit 6e68af6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/producer/groupMessagesPerPartition.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ module.exports = ({ topic, partitionMetadata, messages, partitioner }) => {
return {}
}

return messages.reduce((result, message) => {
const grouping = {}
for (const message of messages) {
const partition = partitioner({ topic, partitionMetadata, message })
const current = result[partition] || []
return Object.assign(result, { [partition]: [...current, message] })
}, {})
if (grouping[partition] === undefined) {
grouping[partition] = []
}
grouping[partition].push(message)
}

return grouping
}

0 comments on commit 6e68af6

Please sign in to comment.