[ISSUE #11414]Optimize ServiceInfo.validate() to reduce memory usage (#11415)

This commit is contained in:
JorringHsiao 2023-11-24 15:48:54 +08:00 committed by GitHub
parent c42981c9e3
commit 44b0891d16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -188,18 +188,14 @@ public class ServiceInfo {
return false;
}
List<Instance> validHosts = new ArrayList<>();
boolean existValidHosts = false;
for (Instance host : hosts) {
if (!host.isHealthy()) {
continue;
}
if (host.getWeight() > 0) {
validHosts.add(host);
if (host.isHealthy() && host.getWeight() > 0) {
existValidHosts = true;
break;
}
}
//No valid hosts, return false.
return !validHosts.isEmpty();
return existValidHosts;
}
@JsonIgnore