847850277 commented on code in PR #4178:
URL: https://github.com/apache/shenyu/pull/4178#discussion_r1023587266


##########
shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/AbstractShenyuPlugin.java:
##########
@@ -79,76 +79,72 @@ public abstract class AbstractShenyuPlugin implements 
ShenyuPlugin {
     @Override
     public Mono<Void> execute(final ServerWebExchange exchange, final 
ShenyuPluginChain chain) {
         initMatchCacheConfig();
-        String pluginName = named();
+        final String pluginName = named();
         PluginData pluginData = 
BaseDataCache.getInstance().obtainPluginData(pluginName);
-        if (Objects.nonNull(pluginData) && pluginData.getEnabled()) {
-            final String path = exchange.getRequest().getURI().getPath();
-            SelectorData selectorData = 
obtainSelectorDataCacheIfEnabled(exchange);
+        // early exit
+        if (Objects.isNull(pluginData) || !pluginData.getEnabled()) {
+            return chain.execute(exchange);
+        }
+        final String path = exchange.getRequest().getURI().getPath();
+        List<SelectorData> selectors = 
BaseDataCache.getInstance().obtainSelectorData(pluginName);
+        SelectorData selectorData = obtainSelectorDataCacheIfEnabled(path);
+        // handle Selector
+        if (Objects.nonNull(selectorData) && 
StringUtils.isBlank(selectorData.getId())) {
+            return handleSelectorIfNull(pluginName, exchange, chain);
+        }
+        if (Objects.isNull(selectorData)) {
+            if (CollectionUtils.isEmpty(selectors)) {
+                return handleSelectorIfNull(pluginName, exchange, chain);
+            }
+            Pair<Boolean, SelectorData> matchSelectorData = 
matchSelector(exchange, selectors);
+            selectorData = matchSelectorData.getRight();
             if (Objects.isNull(selectorData)) {
-                List<SelectorData> selectors = 
BaseDataCache.getInstance().obtainSelectorData(pluginName);
-                if (CollectionUtils.isEmpty(selectors)) {
-                    return handleSelectorIfNull(pluginName, exchange, chain);
-                }
-                Pair<Boolean, SelectorData> matchSelectorData = 
matchSelector(exchange, selectors);
-                selectorData = matchSelectorData.getRight();
-                if (Objects.isNull(selectorData)) {
-                    if (matchCacheConfig.getSelectorEnabled() && 
matchSelectorData.getLeft()) {
-                        selectorData = new SelectorData();
-                        selectorData.setPluginName(named());
-                        cacheSelectorData(path, selectorData);
-                    }
-                    return handleSelectorIfNull(pluginName, exchange, chain);
-                } else {
-                    if (matchCacheConfig.getSelectorEnabled() && 
matchSelectorData.getLeft()) {
-                        cacheSelectorData(path, selectorData);
-                    }
+                if (matchCacheConfig.getSelectorEnabled() && 
matchSelectorData.getLeft()) {
+                    selectorData = new SelectorData();
+                    selectorData.setPluginName(pluginName);
+                    cacheSelectorData(path, selectorData);
                 }
+                return handleSelectorIfNull(pluginName, exchange, chain);
             } else {
-                if (StringUtils.isBlank(selectorData.getId())) {
-                    return handleSelectorIfNull(pluginName, exchange, chain);
+                if (matchCacheConfig.getSelectorEnabled() && 
matchSelectorData.getLeft()) {

Review Comment:
   this is from From the old logic, seem No duplicate cache appears
   
   
![image](https://user-images.githubusercontent.com/12622645/202112154-fccf07a7-f7e6-49ed-ad98-f288328daad3.png)
   
   
![image](https://user-images.githubusercontent.com/12622645/202113037-fa62e8a5-2a93-4dad-b459-d4641157126a.png)
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to