Skip to content
Snippets Groups Projects
Commit 52448ace authored by S.Listl's avatar S.Listl
Browse files

Attribute_entity performance

parent 7dd4a2df
No related branches found
No related tags found
No related merge requests found
......@@ -328,14 +328,14 @@
<onDelete>%aditoprj%/entity/Attribute_entity/recordcontainers/jdito/onDelete.js</onDelete>
<recordFields>
<element>UID.value</element>
<element>ATTRIBUTE_ACTIVE.value</element>
<element>ATTRIBUTE_NAME.value</element>
<element>ATTRIBUTE_PARENT_ID.value</element>
<element>ATTRIBUTE_TYPE.value</element>
<element>ATTRIBUTE_TYPE.displayValue</element>
<element>ATTRIBUTE_ACTIVE.value</element>
<element>KEYWORD_CONTAINER.value</element>
<element>SORTING.value</element>
<element>ATTRIBUTE_TYPE.value</element>
<element>ATTRIBUTE_TYPE.displayValue</element>
<element>USAGELIST.value</element>
<element>ATTRIBUTE_NAME.value</element>
<element>FULL_ATTRIBUTE_NAME.value</element>
</recordFields>
</jDitoRecordContainer>
......
import("Util_lib");
import("JditoFilter_lib");
import("KeywordRegistry_basic");
import("Keyword_lib");
......@@ -7,35 +8,38 @@ import("system.result");
import("Sql_lib");
import("Attribute_lib");
var sqlSelect = "select A.AB_ATTRIBUTEID, A.ATTRIBUTE_ACTIVE, A.ATTRIBUTE_NAME, A.ATTRIBUTE_PARENT_ID, A.ATTRIBUTE_TYPE, "
+ KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.attributeType(), "A.ATTRIBUTE_TYPE")
+ ", A.KEYWORD_CONTAINER, A.SORTING, P.ATTRIBUTE_PARENT_ID, P.ATTRIBUTE_NAME "
+ "from AB_ATTRIBUTE A "
+ "left join AB_ATTRIBUTE P on A.ATTRIBUTE_PARENT_ID = P.AB_ATTRIBUTEID";
var sqlOrder = " order by A.ATTRIBUTE_PARENT_ID asc, A.SORTING asc";
var uidTableAlias = "SELF";
var sqlSelect = "select SELF.AB_ATTRIBUTEID, SELF.ATTRIBUTE_PARENT_ID, SELF.ATTRIBUTE_ACTIVE, SELF.KEYWORD_CONTAINER, SELF.SORTING, SELF.ATTRIBUTE_TYPE, "
+ KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.attributeType(), "SELF.ATTRIBUTE_TYPE") //3
+ ", '', SELF.ATTRIBUTE_NAME, PARENT1.ATTRIBUTE_NAME, PARENT2.ATTRIBUTE_NAME, PARENT2.ATTRIBUTE_PARENT_ID "
+ "from AB_ATTRIBUTE SELF "
+ "left join AB_ATTRIBUTE PARENT1 on SELF.ATTRIBUTE_PARENT_ID = PARENT1.AB_ATTRIBUTEID "
+ "left join AB_ATTRIBUTE PARENT2 ON PARENT1.ATTRIBUTE_PARENT_ID = PARENT2.AB_ATTRIBUTEID";
var condition = SqlCondition.begin();
var sqlOrder = " order by SELF.ATTRIBUTE_PARENT_ID asc, SELF.SORTING asc";
var getGroups = vars.exists("$param.GetGroups_param") && vars.get("$param.GetGroups_param");
var objectType = vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param");
var parentType = vars.exists("$param.AttrParentType_param") && vars.get("$param.AttrParentType_param");
if (vars.exists("$local.idvalues") && vars.get("$local.idvalues"))
condition.and("A.AB_ATTRIBUTEID in ('" + vars.get("$local.idvalues").join("','") + "')");
else if (getGroups)
{
//this is for the selection of the superordinate attribute, this condition
//filters out the own id and the children to prevent loops
condition.and("SELF.AB_ATTRIBUTEID in ('" + vars.get("$local.idvalues").join("','") + "')");
}
else if (getGroups) //if getGroups == true, it is the lookup for selecting the superordinate attribute
{
//this condition filters out the own id and the children to prevent loops
var isGroupCondition = SqlCondition.begin();
for (let type in $AttributeTypes)
if ($AttributeTypes[type].isGroup && $AttributeTypes[type] != $AttributeTypes.COMBO)
isGroupCondition.orPrepare(["AB_ATTRIBUTE", "ATTRIBUTE_TYPE", "A"], $AttributeTypes[type]);
isGroupCondition.orPrepare(["AB_ATTRIBUTE", "ATTRIBUTE_TYPE", uidTableAlias], $AttributeTypes[type]);
condition.andSqlCondition(SqlCondition.begin()
.andSqlCondition(isGroupCondition)
.andPrepareVars(["AB_ATTRIBUTE", "AB_ATTRIBUTEID", "A"], "$param.AttrParentId_param", "# != ?")
.and("A.AB_ATTRIBUTEID not in ('" + AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")).join("','") + "')")
.andPrepareVars(["AB_ATTRIBUTE", "AB_ATTRIBUTEID", uidTableAlias], "$param.AttrParentId_param", "# != ?")
.and("SELF.AB_ATTRIBUTEID not in ('" + AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")).join("','") + "')")
);
}
else if (objectType) //if there's an objectType, it comes from the AttributeRelation entity
......@@ -47,18 +51,17 @@ else if (objectType) //if there's an objectType, it comes from the AttributeRel
if (vars.exists("$param.AttributeCount_param") && vars.get("$param.AttributeCount_param"))
attributeCount = JSON.parse(vars.get("$param.AttributeCount_param"));
var ids = AttributeUtil.getPossibleAttributes(objectType, false, filteredAttributes, attributeCount);
condition.and("A.AB_ATTRIBUTEID in ('" + ids.join("','") + "')");
condition.and("SELF.AB_ATTRIBUTEID in ('" + ids.join("','") + "')");
}
else
else if (parentType)
{
var parentType = vars.exists("$param.AttrParentType_param") && vars.get("$param.AttrParentType_param");
if (AttributeTypeUtil.isGroupType(parentType))
if (AttributeTypeUtil.isGroupType(parentType)) //condition for all subordinate attributes of an attribute
{
var parentId = vars.exists("$param.AttrParentId_param") && vars.get("$param.AttrParentId_param");
if (parentId)
condition.and("A.AB_ATTRIBUTEID in ('" + AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")).join("','") + "')");
condition.and("SELF.AB_ATTRIBUTEID in ('" + AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")).join("','") + "')");
}
else if (parentType)
else
condition.and("1=2");
}
......@@ -66,14 +69,12 @@ else
if (vars.exists("$local.filter") && vars.get("$local.filter"))
{
var filter = vars.get("$local.filter");
condition.andSqlCondition(JditoFilterUtils.getSqlCondition(filter, "AB_ATTRIBUTE", "A"));
condition.andSqlCondition(JditoFilterUtils.getSqlCondition(filter, "AB_ATTRIBUTE", uidTableAlias));
}
var attributes = db.table(condition.buildSql(sqlSelect, "1=1", sqlOrder));
attributes = _buildAttributeTable(attributes);
result.object(attributes);
result.object(_buildAttributeTable(attributes));
//sorts the records in a way that a tree can be built and adds values
......@@ -95,47 +96,41 @@ function _buildAttributeTable (pAttributes)
{
//item will be added if the id is not already in the object and
//the parent is already added (or the parent is not in the array)
if (!(row[0] in this) && (row[3] in this || !allIds[row[3]]))
if (!(row[0] in this) && (row[1] in this || !allIds[row[1]]))
this[row[0]] = {
data : row,
index : arrayIndex++
};
}, rows);
}
var displaySimpleName = vars.exists("$param.DisplaySimpleName_param") && vars.get("$param.DisplaySimpleName_param");
var sortedArray = new Array(Object.keys(rows).length);
for (let i in rows)
{
let rowData = rows[i].data;
if (!(vars.exists("$param.DisplaySimpleName_param") && vars.get("$param.DisplaySimpleName_param")))
rowData[9] = _getFullName(rowData[2], rowData[9], rowData[8]);
else
rowData[9] = rowData[2];
if (rowData[4].trim() != $AttributeTypes.COMBOVALUE)
if (rowData[5].trim() != $AttributeTypes.COMBOVALUE)
{
let usages = db.array(db.COLUMN, SqlCondition.begin()
.andPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", rowData[0])
.buildSql("select OBJECT_TYPE from AB_ATTRIBUTEUSAGE")
);
if (usages.length)
rowData[8] = usages.join(", ");
rowData[7] = usages.join(", ");
}
else
rowData[8] = "";
var fullName = displaySimpleName
? rowData[8]
: _getFullName(rowData[8], rowData[9], rowData[10], rowData[11]);
rowData.splice(9, 3, fullName);
sortedArray[rows[i].index] = rowData;
}
return sortedArray;
}
function _getFullName (pAttributeName, pParentName, pGrandParentId)
function _getFullName (pAttributeName, pParent1Name, pParent2Name, pParent3Id)
{
if (pParentName)
pAttributeName = pParentName + " / " + pAttributeName;
if (pGrandParentId)
{
var grandParentName = AttributeUtil.getFullAttributeName(pGrandParentId);
if (grandParentName)
pAttributeName = grandParentName + " / " + pAttributeName;
}
var parent3FullName = pParent3Id ? AttributeUtil.getFullAttributeName(pParent3Id) : null;
pAttributeName = ArrayUtils.joinNonEmptyFields([parent3FullName, pParent2Name, pParent1Name, pAttributeName], " / ");
return pAttributeName;
}
\ No newline at end of file
......@@ -3,6 +3,6 @@ import("system.vars");
import("system.result");
var title = vars.get("$field.FULL_ATTRIBUTE_NAME");
if (!(vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"))) //the prefix shouldn't be in the lookup
if (!(vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param"))) //TODO: the prefix shouldn't be in the lookup, this condition is a workaround
title = ContextUtils.prefixWithCurrentContextTitle(title);
result.string(title);
\ No newline at end of file
......@@ -3087,6 +3087,9 @@
<entry>
<key>per</key>
</entry>
<entry>
<key>The minimal count can't be larger than the maximal count!</key>
</entry>
</keyValueMap>
<font name="Dialog" style="0" size="11" />
<sqlModels>
......
......@@ -60,7 +60,7 @@
</entry>
<entry>
<key>${ATTRIBUTE_VOID}</key>
<value>Kein Wert</value>
<value>Tag</value>
</entry>
<entry>
<key>Turnover</key>
......
......@@ -3058,7 +3058,7 @@
</entry>
<entry>
<key>${ATTRIBUTE_VOID}</key>
<value>Void</value>
<value>Tag</value>
</entry>
<entry>
<key>Kampagnenzeitraum</key>
......@@ -3121,6 +3121,9 @@
<entry>
<key>per</key>
</entry>
<entry>
<key>The minimal count can't be larger than the maximal count!</key>
</entry>
</keyValueMap>
<font name="Dialog" style="0" size="11" />
</language>
......@@ -359,6 +359,22 @@ ArrayUtils.hasElement = function(targetArray, element, ignoreStringCase) {
return false;
}
/**
* joins an array but skips empty elements (null, undefined, "")
*
* @param {Array} pArray the array to join
* @param {String} [pSeparator=", "] the separator
*
* @return {String} the resulting string
*/
ArrayUtils.joinNonEmptyFields = function (pArray, pSeparator)
{
return pArray.filter(function (element)
{
return element !== null && element !== undefined && element !== "";
}).join(pSeparator);
}
/**
* Class containing utility functions for use with JSON
* @class
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment