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

nvazquez pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new 4dae995455e Improve Inherited Context Lookup in getConfigResources 
(#11048)
4dae995455e is described below

commit 4dae995455e1e920916352c9d59a0553114cbc28
Author: Suyang(Dawson) Chen <[email protected]>
AuthorDate: Tue Oct 27 22:24:42 2026 -0400

    Improve Inherited Context Lookup in getConfigResources (#11048)
    
    * improve the getConfigResources
    
    * revert format changes
    
    * revert format changes
    
    * revert format changes
    
    * return immutable set when def is null
    
    * add final for clarity
    
    * address comment
---
 .../model/impl/DefaultModuleDefinitionSet.java     | 38 +++++++++++++++-------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git 
a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java
 
b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java
index 78693f72140..add33b349aa 100644
--- 
a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java
+++ 
b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.EmptyStackException;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -61,6 +62,9 @@ public class DefaultModuleDefinitionSet implements 
ModuleDefinitionSet {
     String root;
     Map<String, ModuleDefinition> modules;
     Map<String, ApplicationContext> contexts = new HashMap<String, 
ApplicationContext>();
+
+    Map<String, Set<Resource>> inheritedConfigResourcesMap = new 
HashMap<String, Set<Resource>>();
+
     ApplicationContext rootContext = null;
     Set<String> excludes = new HashSet<String>();
     Properties configProperties = null;
@@ -310,24 +314,36 @@ public class DefaultModuleDefinitionSet implements 
ModuleDefinitionSet {
 
     @Override
     public Resource[] getConfigResources(String name) {
-        Set<Resource> resources = new LinkedHashSet<Resource>();
-
-        ModuleDefinition original = null;
-        ModuleDefinition def = original = modules.get(name);
-
-        if (def == null)
+        ModuleDefinition def = modules.get(name);
+        if (def == null) {
             return new Resource[] {};
+        }
+
+        Set<Resource> resources = new LinkedHashSet<>();
 
         resources.addAll(def.getContextLocations());
 
-        while (def != null) {
-            resources.addAll(def.getInheritableContextLocations());
-            def = modules.get(def.getParentName());
+        resources.addAll(collectInheritedResources(def));
+
+        resources.addAll(def.getOverrideContextLocations());
+
+        return resources.toArray(Resource[]::new);
+    }
+
+    private Set<Resource> collectInheritedResources(final ModuleDefinition 
def) {
+        if (def == null) {
+            return Collections.emptySet();
         }
 
-        resources.addAll(original.getOverrideContextLocations());
+        final Set<Resource> cachedResources = 
inheritedConfigResourcesMap.get(def.getName());
+        if (cachedResources != null) {
+            return cachedResources;
+        }
 
-        return resources.toArray(new Resource[resources.size()]);
+        final Set<Resource> inheritableResources = new 
LinkedHashSet<>(def.getInheritableContextLocations());
+        
inheritableResources.addAll(collectInheritedResources(modules.get(def.getParentName())));
+        inheritedConfigResourcesMap.put(def.getName(), inheritableResources);
+        return inheritableResources;
     }
 
     @Override

Reply via email to