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

Attribute performance fix

parent 84fff35b
No related branches found
No related tags found
No related merge requests found
......@@ -256,7 +256,6 @@
<name>USAGELIST</name>
<title>Usage</title>
<state>READONLY</state>
<valueProcess>%aditoprj%/entity/Attribute_entity/entityfields/usagelist/valueProcess.js</valueProcess>
</entityField>
<entityProvider>
<name>AttributeGroups</name>
......@@ -321,6 +320,8 @@
<element>ATTRIBUTE_TYPE.displayValue</element>
<element>KEYWORD_CONTAINER.value</element>
<element>SORTING.value</element>
<element>USAGELIST.value</element>
<element>FULL_ATTRIBUTE_NAME.value</element>
</recordFields>
</jDitoRecordContainer>
</recordContainers>
......
import("system.translate");
import("system.result");
import("system.db");
import("system.vars");
import("Sql_lib");
import("Attribute_lib");
var retStr = "";
if (vars.get("$field.ATTRIBUTE_TYPE").trim() != $AttributeTypes.COMBOVALUE)
{
var usages = db.array(db.COLUMN, SqlCondition.begin()
.andPrepareVars("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", "$field.UID")
.buildSql("select OBJECT_TYPE from AB_ATTRIBUTEUSAGE"));
if (usages.length)
retStr = usages.join(", ");
}
result.string(retStr);
\ No newline at end of file
import("system.datetime");
import("JditoFilter_lib");
import("KeywordRegistry_basic");
import("Keyword_lib");
......@@ -8,33 +7,35 @@ import("system.result");
import("Sql_lib");
import("Attribute_lib");
var sqlSelect = "select AB_ATTRIBUTEID, ATTRIBUTE_ACTIVE, "
+ "ATTRIBUTE_NAME, ATTRIBUTE_PARENT_ID, ATTRIBUTE_TYPE, "
+ KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.attributeType(), "ATTRIBUTE_TYPE")
+ ", KEYWORD_CONTAINER, SORTING from AB_ATTRIBUTE";
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 ATTRIBUTE_PARENT_ID asc, SORTING asc";
var sqlOrder = " order by A.ATTRIBUTE_PARENT_ID asc, A.SORTING asc";
var condition = new SqlCondition();
var condition = SqlCondition.begin();
var getGroups = vars.exists("$param.GetGroups_param") && vars.get("$param.GetGroups_param");
var objectType = vars.exists("$param.ObjectType_param") && vars.get("$param.ObjectType_param");
if (vars.exists("$local.idvalues") && vars.get("$local.idvalues"))
condition.and("AB_ATTRIBUTEID in ('" + vars.get("$local.idvalues").join("','") + "')");
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
var isGroupCondition = new SqlCondition();
var isGroupCondition = SqlCondition.begin();
for (let type in $AttributeTypes)
if ($AttributeTypes[type].isGroup && $AttributeTypes[type] != $AttributeTypes.COMBO)
isGroupCondition.orPrepare("AB_ATTRIBUTE.ATTRIBUTE_TYPE", $AttributeTypes[type]);
isGroupCondition.orPrepare(["AB_ATTRIBUTE", "ATTRIBUTE_TYPE", "A"], $AttributeTypes[type]);
condition.andSqlCondition(SqlCondition.begin()
.andSqlCondition(isGroupCondition)
.andPrepareVars("AB_ATTRIBUTE.AB_ATTRIBUTEID", "$param.AttrParentId_param", "# != ?")
.and("AB_ATTRIBUTE.AB_ATTRIBUTEID not in ('" + AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")).join("','") + "')")
.andPrepareVars(["AB_ATTRIBUTE", "AB_ATTRIBUTEID", "A"], "$param.AttrParentId_param", "# != ?")
.and("A.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
......@@ -44,18 +45,18 @@ else if (objectType) //if there's an objectType, it comes from the AttributeRel
filteredAttributes = JSON.parse(vars.get("$param.FilteredAttributeIds_param"));
var ids = AttributeUtil.getPossibleAttributes(objectType, false, filteredAttributes);
condition.and("AB_ATTRIBUTE.AB_ATTRIBUTEID in ('" + ids.join("','") + "')");
condition.and("A.AB_ATTRIBUTEID in ('" + ids.join("','") + "')");
}
else
{
var type = vars.exists("$param.AttrParentType_param") && vars.get("$param.AttrParentType_param");
if (AttributeTypeUtil.isGroupType(type))
var parentType = vars.exists("$param.AttrParentType_param") && vars.get("$param.AttrParentType_param");
if (AttributeTypeUtil.isGroupType(parentType))
{
var parentId = vars.exists("$param.AttrParentId_param") && vars.get("$param.AttrParentId_param");
if (parentId)
condition.and("AB_ATTRIBUTE.AB_ATTRIBUTEID in ('" + AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")).join("','") + "')");
condition.and("A.AB_ATTRIBUTEID in ('" + AttributeUtil.getAllChildren(vars.getString("$param.AttrParentId_param")).join("','") + "')");
}
else if (type)
else if (parentType)
condition.and("1=2");
}
......@@ -63,45 +64,79 @@ else
if (vars.exists("$local.filter") && vars.get("$local.filter"))
{
var filter = vars.get("$local.filter");
condition.andSqlCondition(JditoFilterUtils.getSqlCondition(filter, "AB_ATTRIBUTE"));
condition.andSqlCondition(JditoFilterUtils.getSqlCondition(filter, "AB_ATTRIBUTE", "A"));
}
var attributes = db.table(condition.buildSql(sqlSelect, "1=1", sqlOrder));
if (attributes.length > 1)
attributes = _sortArrayForTree(attributes);
var usageIdType = SqlUtils.getSingleColumnType("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID");
var attributeIdType = SqlUtils.getSingleColumnType("AB_ATTRIBUTE.AB_ATTRIBUTEID");
attributes = _buildAttributeTable(attributes);
result.object(attributes);
//sorts the records in a way that a tree can be built
function _sortArrayForTree (pArray)
//sorts the records in a way that a tree can be built and adds values
function _buildAttributeTable (pAttributes)
{
var rows = {};
var allIds = {};
var idIndex = 0;
var parentIdIndex = 3;
pArray.forEach(function (row) {allIds[row[idIndex]] = true;});
//fills the allIds object, the object is used for checking if a parent exists in the array
pAttributes.forEach(function (row) {allIds[row[0]] = true;});
var index = 0;
var arrayIndex = 0;
for (let itemsAdded = true; itemsAdded; itemsAdded = oldIndex != index)
//stops the loop when no new items were added so that recursive relations between attributes don't cause an infinite loop
for (let itemsAdded = true; itemsAdded; itemsAdded = oldIndex != arrayIndex)
{
var oldIndex = index;
pArray.forEach(function (row)
{
var oldIndex = arrayIndex;
pAttributes.forEach(function (row)
{
//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[idIndex] in this) && (row[parentIdIndex] in this || !allIds[row[parentIdIndex]]))
this[row[idIndex]] = {
if (!(row[0] in this) && (row[3] in this || !allIds[row[3]]))
this[row[0]] = {
data : row,
index : index++
index : arrayIndex++
};
}, rows);
}
var sortedArray = new Array(Object.keys(rows).length);
for (let i in rows)
sortedArray[rows[i].index] = rows[i].data;
{
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)
{
let usages = db.array(db.COLUMN, SqlCondition.begin()
.andPrepare("AB_ATTRIBUTEUSAGE.AB_ATTRIBUTE_ID", rowData[0], null, usageIdType)
.buildSql("select OBJECT_TYPE from AB_ATTRIBUTEUSAGE")
);
if (usages.length)
rowData[8] = usages.join(", ");
}
else
rowData[8] = "";
sortedArray[rows[i].index] = rowData;
}
return sortedArray;
}
function _getFullName (pAttributeName, pParentName, pGrandParentId)
{
if (pParentName)
pAttributeName = pParentName + " / " + pAttributeName;
if (pGrandParentId)
{
var grandParentName = AttributeUtil.getFullAttributeName(pGrandParentId, null, attributeIdType);
if (grandParentName)
pAttributeName = grandParentName + " / " + pAttributeName;
}
return pAttributeName;
}
\ No newline at end of file
......@@ -117,6 +117,7 @@ JditoFilterUtils.filterRecords = function (pColumns, pRecords, pFilter)
*
* @param {String|Object} pFilter the filter as JSON
* @param {String} pTable the database table
* @param {String} [pTableAlias=null] the database table alias
* @param {Object} [pColumnMap=null] custom mapping for the fields to the DB columns, this is necessary
* if the fields are from different tables
*
......@@ -129,7 +130,7 @@ JditoFilterUtils.filterRecords = function (pColumns, pRecords, pFilter)
*
* @return {SqlCondition} the SqlCondition object
*/
JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pColumnMap)
JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pTableAlias, pColumnMap)
{
var condition = new SqlCondition();
......@@ -152,8 +153,10 @@ JditoFilterUtils.getSqlCondition = function (pFilter, pTable, pColumnMap)
{
if (pCondition.name in pColumnMap)
pCondition.name = pColumnMap[pCondition.name];
else if (pTable && pTableAlias)
pCondition.name = [pTable, pCondition.name, pTableAlias];
else if (pTable)
pCondition.name = pTable + "." + pCondition.name;
pCondition.name = pTable + "." + pCondition.name;
pCondition.value = (pCondition.key || pCondition.value);
var condition = _getCondition.call(pCondition);
......
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