Skip to content

Commit ba36762

Browse files
author
paragrf
committed
feature:optimize performance of getPartitions
1 parent 6be10e0 commit ba36762

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/main/java/io/lettuce/core/cluster/PartitionsConsensusImpl.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package io.lettuce.core.cluster;
22

3-
import java.util.ArrayList;
4-
import java.util.Collections;
5-
import java.util.List;
6-
import java.util.Map;
3+
import java.util.*;
74

85
import io.lettuce.core.RedisURI;
96
import io.lettuce.core.cluster.models.partitions.Partitions;
@@ -31,12 +28,16 @@ Partitions getPartitions(Partitions current, Map<RedisURI, Partitions> topologyV
3128

3229
List<VotedPartitions> votedList = new ArrayList<>();
3330

31+
Map<String, RedisClusterNode> nodes = new HashMap<>(current.size());
32+
for (RedisClusterNode knownNode : current) {
33+
nodes.put(knownNode.getNodeId(), knownNode);
34+
}
35+
3436
for (Partitions partitions : topologyViews.values()) {
3537

3638
int knownNodes = 0;
37-
for (RedisClusterNode knownNode : current) {
38-
39-
if (partitions.getPartitionByNodeId(knownNode.getNodeId()) != null) {
39+
for(RedisClusterNode node : partitions){
40+
if(nodes.containsKey(node.getNodeId())){
4041
knownNodes++;
4142
}
4243
}

0 commit comments

Comments
 (0)