From 5f22f7f4958ce889c2b5996f67c2fc87432910b1 Mon Sep 17 00:00:00 2001 From: hengsin Date: Wed, 15 Sep 2021 19:00:28 +0800 Subject: [PATCH] IDEMPIERE-4961 Minor performance enhancement for AD Window (#878) * IDEMPIERE-4961 Minor performance enhancement for AD Window * IDEMPIERE-4961 Minor performance enhancement for AD Window Fix potential mtab not found issue with 2pack import. --- .../adempiere/impexp/GridTabCSVExporter.java | 2 +- .../adempiere/model/GenericZoomProvider.java | 2 +- .../src/org/compiere/model/MTab.java | 24 +++++++++++++++++++ .../webui/adwindow/ADWindowToolbar.java | 5 ++++ .../src/org/adempiere/webui/apps/AEnv.java | 13 ++++++++++ .../webui/panel/CustomizeGridViewPanel.java | 2 +- .../adempiere/webui/panel/HelpController.java | 2 +- .../panel/QuickCustomizeGridViewPanel.java | 2 +- 8 files changed, 47 insertions(+), 5 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVExporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVExporter.java index 3a189cd5eb..2df94b6b76 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVExporter.java @@ -331,7 +331,7 @@ public class GridTabCSVExporter implements IGridTabExporter private String isValidTabToExport(GridTab gridTab){ String result=null; - MTab tab = new MTab(Env.getCtx(), gridTab.getAD_Tab_ID(), null); + MTab tab = MTab.get(gridTab.getAD_Tab_ID()); if (tab.isReadOnly()) result = Msg.getMsg(Env.getCtx(),"FieldIsReadOnly", new Object[] {gridTab.getName()}); diff --git a/org.adempiere.base/src/org/adempiere/model/GenericZoomProvider.java b/org.adempiere.base/src/org/adempiere/model/GenericZoomProvider.java index fec3bcb007..769153485e 100644 --- a/org.adempiere.base/src/org/adempiere/model/GenericZoomProvider.java +++ b/org.adempiere.base/src/org/adempiere/model/GenericZoomProvider.java @@ -171,7 +171,7 @@ public class GenericZoomProvider implements IZoomProvider { int tabIDLoop = AD_Tab_ID; int levelUp = 0; while (true) { - MTab tab = new MTab(ctx, tabIDLoop, null); + MTab tab = MTab.get(tabIDLoop); String whereCtx = tab.getWhereClause(); if (!Util.isEmpty(whereCtx, true)) { if (whereCtx.indexOf("@") != -1) diff --git a/org.adempiere.base/src/org/compiere/model/MTab.java b/org.adempiere.base/src/org/compiere/model/MTab.java index 0c33525515..b7c5f373c6 100644 --- a/org.adempiere.base/src/org/compiere/model/MTab.java +++ b/org.adempiere.base/src/org/compiere/model/MTab.java @@ -28,6 +28,7 @@ import org.adempiere.exceptions.FillMandatoryException; import org.compiere.util.CLogger; import org.compiere.util.DB; import org.compiere.util.Env; +import org.idempiere.cache.ImmutableIntPOCache; import org.idempiere.cache.ImmutablePOSupport; /** @@ -46,6 +47,29 @@ public class MTab extends X_AD_Tab implements ImmutablePOSupport */ private static final long serialVersionUID = -8111075325920938135L; + /** Cache */ + private static ImmutableIntPOCache s_cache = new ImmutableIntPOCache(Table_Name, 20); + + /** + * + * @param AD_Tab_ID + * @return {@link MTab} + */ + public static MTab get(int AD_Tab_ID) + { + Integer key = Integer.valueOf(AD_Tab_ID); + MTab retValue = s_cache.get (Env.getCtx(), key, e -> new MTab(Env.getCtx(), e)); + if (retValue != null) + return retValue; + + retValue = new MTab (Env.getCtx(), AD_Tab_ID, (String)null); + if (retValue.get_ID () == AD_Tab_ID) { + s_cache.put (key, retValue); + return retValue; + } + return null; + } + /** * Standard Constructor * @param ctx context diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java index 53f07eea3c..b428a44dda 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADWindowToolbar.java @@ -30,6 +30,7 @@ import org.adempiere.webui.ClientInfo; import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.action.Actions; import org.adempiere.webui.action.IAction; +import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.component.Combobox; import org.adempiere.webui.component.FToolbar; import org.adempiere.webui.component.Tabpanel; @@ -1213,6 +1214,10 @@ public class ADWindowToolbar extends FToolbar implements EventListener } public void refreshUserQuery(int AD_Tab_ID, int AD_UserQuery_ID) { + if (AEnv.getOrSetExecutionAttribute(getClass().getName()+".refreshUserQuery")) { + return; + } + fQueryName.getItems().clear(); userQueries = MUserQuery.get(Env.getCtx(), AD_Tab_ID); fQueryName.appendItem(""); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java index 9c3eb6b93c..b824c07431 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/AEnv.java @@ -816,4 +816,17 @@ public final class AEnv return getApplicationUrl() + "?Action=Zoom&TableName" + po.get_TableName() + "&Record_ID=" + po.get_ID(); } + /** + * + * @param attribute + * @return true if attribute have been set for current executions + */ + public static boolean getOrSetExecutionAttribute(String attribute) { + if (Executions.getCurrent() != null) { + if (Executions.getCurrent().getAttribute(attribute) != null) + return true; + Executions.getCurrent().setAttribute(attribute, Boolean.TRUE); + } + return false; + } } // AEnv diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/CustomizeGridViewPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/CustomizeGridViewPanel.java index ad6b32fa5a..6d06af0c2e 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/CustomizeGridViewPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/CustomizeGridViewPanel.java @@ -352,7 +352,7 @@ public class CustomizeGridViewPanel extends Panel { List lsFieldsOfGrid = query.list(); HashMap curTabSel = new HashMap(); - MTab tab = new MTab(Env.getCtx(), m_AD_Tab_ID, null); + MTab tab = MTab.get(m_AD_Tab_ID); for (MField field : lsFieldsOfGrid) { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java index fd184433d1..ff98970264 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java @@ -285,7 +285,7 @@ public class HelpController if (ctxType.equals(X_AD_CtxHelp.CTXTYPE_Tab)) { - MTab tab = new MTab(Env.getCtx(), recordId, null); + MTab tab = MTab.get(recordId); if (!Env.isBaseLanguage(Env.getCtx(), "AD_Tab")) { nameMsg = tab.get_Translation("Name", false); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/QuickCustomizeGridViewPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/QuickCustomizeGridViewPanel.java index 646386a5a1..0fe80e229e 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/QuickCustomizeGridViewPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/QuickCustomizeGridViewPanel.java @@ -237,7 +237,7 @@ public class QuickCustomizeGridViewPanel extends Panel { try { List lsFieldsOfGrid = query.list(); HashMap curTabSel = new HashMap(); - MTab tab = new MTab(Env.getCtx(), m_AD_Tab_ID, null); + MTab tab = MTab.get(m_AD_Tab_ID); for (MField field : lsFieldsOfGrid) { if (!MRole.getDefault(Env.getCtx(), false).isColumnAccess(tab.getAD_Table_ID(), field.getAD_Column_ID(),