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

xiaoyu 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 890ac76ab Optimize consul, when the metadata does not change, do not 
perform metadata updates (#4832)
890ac76ab is described below

commit 890ac76aba580f9d854a7240cff1bb55ad57b72a
Author: xuziyang <[email protected]>
AuthorDate: Wed Jul 12 10:43:51 2023 +0800

    Optimize consul, when the metadata does not change, do not perform metadata 
updates (#4832)
---
 .../client/consul/ConsulClientRegisterRepository.java         | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git 
a/shenyu-register-center/shenyu-register-client/shenyu-register-client-consul/src/main/java/org/apache/shenyu/register/client/consul/ConsulClientRegisterRepository.java
 
b/shenyu-register-center/shenyu-register-client/shenyu-register-client-consul/src/main/java/org/apache/shenyu/register/client/consul/ConsulClientRegisterRepository.java
index 16f233e1d..c92eb3731 100644
--- 
a/shenyu-register-center/shenyu-register-client/shenyu-register-client-consul/src/main/java/org/apache/shenyu/register/client/consul/ConsulClientRegisterRepository.java
+++ 
b/shenyu-register-center/shenyu-register-client/shenyu-register-client-consul/src/main/java/org/apache/shenyu/register/client/consul/ConsulClientRegisterRepository.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
 import java.util.Objects;
 import java.util.Properties;
 
+import com.ecwid.consul.v1.kv.model.GetValue;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.common.constant.Constants;
 
@@ -159,6 +160,16 @@ public class ConsulClientRegisterRepository implements 
ShenyuClientRegisterRepos
         String metadataNodeName = buildMetadataNodeName(metadata);
         String metaDataPath = 
RegisterPathConstants.buildMetaDataParentPath(rpcType, contextPath);
         String realNode = RegisterPathConstants.buildRealNode(metaDataPath, 
metadataNodeName);
+
+        GetValue oldValue = consulClient.getKVValue(realNode).getValue();
+        // no change in metadata, no need to update
+        if (oldValue != null) {
+            MetaDataRegisterDTO oldMetaData = 
GsonUtils.getInstance().fromJson(oldValue.getDecodedValue(), 
MetaDataRegisterDTO.class);
+            if (Objects.equals(oldMetaData, metadata)) {
+                return;
+            }
+        }
+        // update metadata
         String metadataJson = GsonUtils.getInstance().toJson(metadata);
         consulClient.setKVValue(realNode, metadataJson);
     }

Reply via email to