You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ra...@apache.org on 2021/09/10 06:28:32 UTC

[dubbo-admin] branch develop updated: Reduce nacos mapping service storage (#817)

This is an automated email from the ASF dual-hosted git repository.

ranke pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-admin.git


The following commit(s) were added to refs/heads/develop by this push:
     new 0f255b0  Reduce nacos mapping service storage (#817)
0f255b0 is described below

commit 0f255b08c3215e7751ddbae3087f264a746f3977
Author: haoyann <10...@qq.com>
AuthorDate: Fri Sep 10 14:28:23 2021 +0800

    Reduce nacos mapping service storage (#817)
---
 .../registry/mapping/impl/NacosServiceMapping.java    | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/registry/mapping/impl/NacosServiceMapping.java b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/registry/mapping/impl/NacosServiceMapping.java
index 6749da6..a7d25c9 100644
--- a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/registry/mapping/impl/NacosServiceMapping.java
+++ b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/registry/mapping/impl/NacosServiceMapping.java
@@ -40,6 +40,7 @@ import java.util.Set;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_LOAD_CACHE_AT_START;
 import static org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY;
@@ -95,7 +96,7 @@ public class NacosServiceMapping implements ServiceMapping {
     public void listenerAll() {
 
         try {
-            anyServices = getAllServiceNames();
+            anyServices = getAllServiceNames().stream().filter(this::filterApplication).collect(Collectors.toSet());
         } catch (Exception e) {
             LOGGER.error("Get nacos all services fail ", e);
         }
@@ -106,7 +107,7 @@ public class NacosServiceMapping implements ServiceMapping {
             try {
                 Set<String> serviceNames = getAllServiceNames();
                 for (String serviceName : serviceNames) {
-                    if (anyServices.add(serviceName)) {
+                    if (filterApplication(serviceName) && anyServices.add(serviceName)) {
                         notifyMappingChangedEvent(serviceName);
                     }
                 }
@@ -145,16 +146,20 @@ public class NacosServiceMapping implements ServiceMapping {
         return serviceNames;
     }
 
-    private void notifyMappingChangedEvent(String service) {
-        if (StringUtils.isBlank(service)) {
-            return;
+    private boolean filterApplication(String serviceName) {
+        if (StringUtils.isBlank(serviceName)) {
+            return false;
         }
         for (String category : ALL_SUPPORTED_CATEGORIES) {
             String prefix = category + SERVICE_NAME_SEPARATOR;
-            if (service.startsWith(prefix)) {
-                return;
+            if (serviceName.startsWith(prefix)) {
+                return false;
             }
         }
+        return true;
+    }
+
+    private void notifyMappingChangedEvent(String service) {
         MappingChangedEvent event = new MappingChangedEvent(null, Sets.newHashSet(service));
         for (MappingListener listener : listeners) {
             listener.onEvent(event);