This is an automated email from the ASF dual-hosted git repository.
liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 1b9492bf26 [type:optimize] Optimize instance comparison logic in
NacosInstanceRegisterRepository (#6153)
1b9492bf26 is described below
commit 1b9492bf266b84d320e339b41461223d7014374f
Author: yqw570994511 <[email protected]>
AuthorDate: Sat Sep 13 17:33:23 2025 +0800
[type:optimize] Optimize instance comparison logic in
NacosInstanceRegisterRepository (#6153)
Co-authored-by: yuqianwei <qq120405>
Co-authored-by: aias00 <[email protected]>
---
.../shenyu/registry/nacos/NacosInstanceRegisterRepository.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git
a/shenyu-registry/shenyu-registry-nacos/src/main/java/org/apache/shenyu/registry/nacos/NacosInstanceRegisterRepository.java
b/shenyu-registry/shenyu-registry-nacos/src/main/java/org/apache/shenyu/registry/nacos/NacosInstanceRegisterRepository.java
index 403e9d38d5..78405f843c 100644
---
a/shenyu-registry/shenyu-registry-nacos/src/main/java/org/apache/shenyu/registry/nacos/NacosInstanceRegisterRepository.java
+++
b/shenyu-registry/shenyu-registry-nacos/src/main/java/org/apache/shenyu/registry/nacos/NacosInstanceRegisterRepository.java
@@ -38,6 +38,7 @@ import org.slf4j.LoggerFactory;
import java.net.URI;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -132,7 +133,7 @@ public class NacosInstanceRegisterRepository implements
ShenyuInstanceRegisterRe
try {
List<Instance> previousInstances =
instanceListMap.get(key);
List<Instance> currentInstances =
namingService.selectInstances(key, groupName, true);
- compareInstances(previousInstances, currentInstances,
listener);
+ compareInstances(new HashSet<>(previousInstances), new
HashSet<>(currentInstances), listener);
instanceListMap.put(key, currentInstances);
} catch (NacosException e) {
throw new ShenyuException(e);
@@ -163,7 +164,7 @@ public class NacosInstanceRegisterRepository implements
ShenyuInstanceRegisterRe
}
}
- private void compareInstances(final List<Instance> previousInstances,
final List<Instance> currentInstances, final ChangedEventListener listener) {
+ private void compareInstances(final Set<Instance> previousInstances, final
Set<Instance> currentInstances, final ChangedEventListener listener) {
Set<Instance> addedInstances = currentInstances.stream()
.filter(item -> !previousInstances.contains(item))
.collect(Collectors.toSet());