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

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new c2cb522b54 Improved: Ofbiz performance issue with ThemeFactory (OFBIZ-)
c2cb522b54 is described below

commit c2cb522b54a73f3ea596ab4c289a067eac08ad55
Author: Jacques Le Roux <jacques.le.r...@les7arts.com>
AuthorDate: Sun Jun 16 18:16:18 2024 +0200

    Improved: Ofbiz performance issue with ThemeFactory (OFBIZ-)
    
    If there are many products with images (images stored in the plugin or 
theme),
    the ThemeFactory blocks the frontend until all files are processed.
    
    The problem is initiated in the following lines of code in 
ThemeFactory.java:
    
    List<File> xmlThemes = FileUtil.findXmlFiles(themeFolderPath,
    null, "theme", "widget-theme.xsd");
    List<File> xmlPluginThemes = FileUtil.findXmlFiles(pluginsFolderPath,
    null, "theme", "widget-theme.xsd");
    
    I think the search path should be restricted to the "widget" folder of the
    respective plugins/themes, as the theme.xml file should be located there.
    
    Thanks: Ingo Wolfmayr
---
 .../apache/ofbiz/widget/model/ThemeFactory.java    | 35 ++++++++++++++++++----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java
 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java
index 62d23d603f..abfd305737 100644
--- 
a/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java
+++ 
b/framework/widget/src/main/java/org/apache/ofbiz/widget/model/ThemeFactory.java
@@ -95,6 +95,32 @@ public final class ThemeFactory {
         }
     }
 
+    /**
+     * Helper method for getThemeXmlFiles
+     * @return
+     * @throws IOException
+     */
+    private static List<File> checkForWidgetFolder(String folderPath) throws 
IOException {
+        File folder = new File(folderPath);
+        List<File> xmlThemes = new ArrayList<File>();
+        if (folder.exists() && folder.isDirectory()) {
+            File[] subFolders = folder.listFiles(File::isDirectory);
+
+            if (subFolders != null) {
+                for (File subFolder : subFolders) {
+                    File widgetFolder = new File(subFolder, "widget");
+                    if (widgetFolder.exists() && widgetFolder.isDirectory()) {
+                        List<File> xmlPluginThemes = 
FileUtil.findXmlFiles(widgetFolder.getPath(), null, "theme", 
"widget-theme.xsd");
+                        if (UtilValidate.isNotEmpty(xmlPluginThemes)) {
+                            xmlThemes.addAll(xmlPluginThemes);
+                        }
+                    }
+                }
+            }
+        }
+        return xmlThemes;
+    }
+
     /**
      * Scan all Theme.xml definition
      * @return
@@ -104,11 +130,10 @@ public final class ThemeFactory {
         String ofbizHome = System.getProperty("ofbiz.home");
         String themeFolderPath = ofbizHome + "/themes";
         String pluginsFolderPath = ofbizHome + "/plugins";
-        List<File> xmlThemes = FileUtil.findXmlFiles(themeFolderPath, null, 
"theme", "widget-theme.xsd");
-        List<File> xmlPluginThemes = FileUtil.findXmlFiles(pluginsFolderPath, 
null, "theme", "widget-theme.xsd");
-        if (UtilValidate.isNotEmpty(xmlPluginThemes)) {
-            xmlThemes.addAll(xmlPluginThemes);
-        }
+
+        List<File> xmlThemes = checkForWidgetFolder(themeFolderPath);
+        xmlThemes.addAll(checkForWidgetFolder(pluginsFolderPath));
+
         return xmlThemes;
     }
 

Reply via email to