IDEMPIERE-4958 Performance improvement for the opening of process dialog (#874)

* IDEMPIERE-4958 Performance improvement for the opening of process dialog

* IDEMPIERE-4958 Performance improvement for the opening of process dialog

Query.scroll and Query.list has similar db performance, the previous
change is not needed.
This commit is contained in:
hengsin 2021-09-14 20:09:55 +08:00 committed by GitHub
parent 4b8af33c4e
commit 21c07785e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 67 deletions

View File

@ -412,6 +412,12 @@ public class MPInstance extends X_AD_PInstance
return ip;
}
@Override
public I_AD_Process getAD_Process() throws RuntimeException {
return MProcess.get(getAD_Process_ID());
}
public static void publishChangedEvent(int AD_User_ID) {
IMessageService service = Core.getMessageService();
if (service != null) {
@ -447,13 +453,15 @@ public class MPInstance extends X_AD_PInstance
// unnamed instances
int lastRunCount = MSysConfig.getIntValue(MSysConfig.LASTRUN_RECORD_COUNT, 5, Env.getAD_Client_ID(ctx));
if (lastRunCount > 0) {
int maxLoopCount = 10 * lastRunCount;
// using JDBC instead of Query for performance reasons, AD_PInstance can be huge
String sql = "SELECT * FROM AD_PInstance "
+ " WHERE AD_Process_ID=? AND AD_User_ID=? AND IsActive='Y' AND AD_Client_ID=? AND Name IS NULL"
+ " ORDER BY Created DESC";
PreparedStatement pstmt = null;
ResultSet rs = null;
int cnt = 0;
int runCount = 0;
int loopCount = 0;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setFetchSize(lastRunCount);
@ -462,16 +470,19 @@ public class MPInstance extends X_AD_PInstance
pstmt.setInt(3, Env.getAD_Client_ID(ctx));
rs = pstmt.executeQuery();
while (rs.next()) {
loopCount++;
MPInstance unnamedInstance = new MPInstance(ctx, rs, null);
String paramsStr = unnamedInstance.getParamsStr();
if (! paramsStrAdded.contains(paramsStr)) {
unnamedInstance.setName(Msg.getMsg(ctx, "LastRun") + " " + unnamedInstance.getCreated());
list.add(unnamedInstance);
paramsStrAdded.add(paramsStr);
cnt++;
if (cnt == lastRunCount)
runCount++;
if (runCount == lastRunCount)
break;
}
if (loopCount == maxLoopCount)
break;
}
} catch (Exception e)
{

View File

@ -34,7 +34,7 @@ import org.compiere.util.DB;
* <li>FR [ 1984834 ] Add POResultSet.hasNext convenient method
* <li>FR [ 1985134 ] POResultSet improvements
*/
public class POResultSet<T extends PO> {
public class POResultSet<T extends PO> implements AutoCloseable {
private String trxName;
private ResultSet resultSet;

View File

@ -16,9 +16,6 @@ package org.adempiere.webui.apps;
import java.io.File;
import java.io.FileInputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@ -82,7 +79,6 @@ import org.compiere.process.ProcessInfoUtil;
import org.compiere.process.ServerProcessCtl;
import org.compiere.util.AdempiereSystemError;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Msg;
@ -169,65 +165,35 @@ public abstract class AbstractProcessDialog extends Window implements IProcessUI
log.config("");
//
StringBuilder buildMsg = new StringBuilder();
boolean trl = !Env.isBaseLanguage(m_ctx, "AD_Process");
String sql = "SELECT Name, Description, Help, IsReport, ShowHelp, AD_Process_UU "
+ "FROM AD_Process "
+ "WHERE AD_Process_ID=?";
if (trl)
sql = "SELECT t.Name, t.Description, t.Help, p.IsReport, p.ShowHelp, AD_Process_UU "
+ "FROM AD_Process p, AD_Process_Trl t "
+ "WHERE p.AD_Process_ID=t.AD_Process_ID"
+ " AND p.AD_Process_ID=? AND t.AD_Language=?";
MProcess process = MProcess.get(AD_Process_ID);
m_Name = trl ? process.get_Translation(MProcess.COLUMNNAME_Name) : process.getName();
m_Description = trl ? process.get_Translation(MProcess.COLUMNNAME_Description) : process.getDescription();
m_Help = trl ? process.get_Translation(MProcess.COLUMNNAME_Help) : process.getHelp();
m_ShowHelp = process.getShowHelp();
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Process_ID);
if (trl)
pstmt.setString(2, Env.getAD_Language(m_ctx));
rs = pstmt.executeQuery();
StringBuilder buildMsg = new StringBuilder();
if (rs.next())
{
m_Name = rs.getString(1);
m_Description = rs.getString(2);
m_Help = rs.getString(3);
m_ShowHelp = rs.getString(5);
// User Customization
MUserDefProc userDef = MUserDefProc.getBestMatch(ctx, AD_Process_ID);
if (userDef != null) {
if (userDef.getName() != null)
m_Name = userDef.getName();
if (userDef.getDescription() != null)
m_Description = userDef.getDescription();
if (userDef.getHelp() != null)
m_Help = userDef.getHelp();
}
buildMsg.append("<b>");
buildMsg.append(Util.isEmpty(m_Description) ? Msg.getMsg(m_ctx, "StartProcess?") : m_Description);
buildMsg.append("</b>");
if (!Util.isEmpty(m_Help))
buildMsg.append("<p>").append(m_Help).append("</p>");
m_AD_Process_UU = rs.getString(6);
}
initialMessage = buildMsg.toString();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
return false;
}
finally
{
DB.close(rs, pstmt);
// User Customization
MUserDefProc userDef = MUserDefProc.getBestMatch(ctx, AD_Process_ID);
if (userDef != null) {
if (userDef.getName() != null)
m_Name = userDef.getName();
if (userDef.getDescription() != null)
m_Description = userDef.getDescription();
if (userDef.getHelp() != null)
m_Help = userDef.getHelp();
}
buildMsg.append("<b>");
buildMsg.append(Util.isEmpty(m_Description) ? Msg.getMsg(m_ctx, "StartProcess?") : m_Description);
buildMsg.append("</b>");
if (!Util.isEmpty(m_Help))
buildMsg.append("<p>").append(m_Help).append("</p>");
m_AD_Process_UU = process.getAD_Process_UU();
initialMessage = buildMsg.toString();
if (m_Name == null)
return false;
//
@ -472,12 +438,12 @@ public abstract class AbstractProcessDialog extends Window implements IProcessUI
}
protected boolean isReport () {
MProcess pr = new MProcess(m_ctx, m_AD_Process_ID, null);
MProcess pr = MProcess.get(m_ctx, m_AD_Process_ID);
return pr.isReport() && pr.getJasperReport() == null;
}
protected boolean isJasperReport () {
MProcess pr = new MProcess(m_ctx, m_AD_Process_ID, null);
MProcess pr = MProcess.get(m_ctx, m_AD_Process_ID);
return pr.isReport() && pr.getJasperReport() != null;
}
@ -548,7 +514,7 @@ public abstract class AbstractProcessDialog extends Window implements IProcessUI
int AD_Column_ID = 0;
boolean m_isCanExport = false;
MProcess pr = new MProcess(m_ctx, m_AD_Process_ID, null);
MProcess pr = MProcess.get(m_ctx, m_AD_Process_ID);
int table_ID = 0;
try
{

View File

@ -64,7 +64,7 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop
*/
public void onMenuSelected(int menuId)
{
MMenu menu = new MMenu(Env.getCtx(), menuId, null);
MMenu menu = MMenu.get(menuId);
try
{