IDEMPIERE-6102 Performance: avoid SQL on AD_TreeNode when the table doesn't have a custom tree (#2309)

This commit is contained in:
Carlos Ruiz 2024-04-11 05:53:44 +02:00
parent 7cd0c88e3a
commit fb594a5f56
2 changed files with 32 additions and 6 deletions

View File

@ -67,7 +67,11 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
/**
*
*/
private static final long serialVersionUID = -167824144142429242L;
private static final long serialVersionUID = -2459194178797758731L;
/**
*
*/
public final static int MAX_OFFICIAL_ID = 999999;
@ -1098,6 +1102,20 @@ public class MTable extends X_AD_Table implements ImmutablePOSupport
return indexName.toString();
}
private Boolean hasCustomTree = null;
/**
* If the table has a custom tree defined
* @return
*/
public boolean hasCustomTree() {
if (hasCustomTree == null) {
int exists = DB.getSQLValueEx(get_TrxName(), "SELECT 1 FROM AD_Tree WHERE TreeType=? AND AD_Table_ID=? AND IsActive='Y'", MTree_Base.TREETYPE_CustomTable, getAD_Table_ID());
hasCustomTree = Boolean.valueOf(exists == 1);
}
return hasCustomTree.booleanValue();
}
/**
* Get Partition Name of the table of the given level
* @param tableName

View File

@ -2641,10 +2641,10 @@ public abstract class PO
// table with potential tree
if (get_ColumnIndex("IsSummary") >= 0) {
if (newRecord)
if (newRecord && getTable().hasCustomTree())
insert_Tree(MTree_Base.TREETYPE_CustomTable);
int idxValue = get_ColumnIndex("Value");
if (newRecord || (idxValue >= 0 && is_ValueChanged(idxValue)))
if (getTable().hasCustomTree() && (newRecord || (idxValue >= 0 && is_ValueChanged(idxValue))))
update_Tree(MTree_Base.TREETYPE_CustomTable);
}
}
@ -2749,8 +2749,16 @@ public abstract class PO
} // saveFinish
/**
* Update Value or create new record.
* To reload call load() - not updated
* Get the MTable object associated to this PO
* @return MTable
*/
private MTable getTable() {
return MTable.get(getCtx(), get_TableName());
}
/**
* Update or insert new record.<br/>
* To reload call load().
* @param trxName transaction
* @return true if saved
*/
@ -4063,7 +4071,7 @@ public abstract class PO
{
//
deleteTranslations(localTrxName);
if (get_ColumnIndex("IsSummary") >= 0) {
if (get_ColumnIndex("IsSummary") >= 0 && getTable().hasCustomTree()) {
delete_Tree(MTree_Base.TREETYPE_CustomTable);
}