From fe7614d9dd6a1ada8e61dad09f94c2ec3fb25336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20V=C3=B6gl?= <a.voegl@adito.de> Date: Tue, 15 Dec 2020 17:27:57 +0000 Subject: [PATCH] [Projekt: Entwicklung - xRM][TicketNr.: 1069706][Ermittlung der Commrestrictions verschlechtert Performance der Personenmaske erheblich] --- process/Contact_lib/process.js | 31 ++++++++++++--------------- process/Sql_lib/process.js | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/process/Contact_lib/process.js b/process/Contact_lib/process.js index 7bbafdc693..4a59839543 100644 --- a/process/Contact_lib/process.js +++ b/process/Contact_lib/process.js @@ -528,10 +528,8 @@ ContactUtils.hasCommRestriction = function(pContactId, pMedium, pStartDate) */ ContactUtils.getActiveCommRestrictionsSubselect = function() { - var mediumList = KeywordUtils.getEntryNamesAndIdsByContainer($KeywordRegistry.communicationMediumCampaign()); - var sqlMasking = new SqlMaskingUtils(); - - var parts = []; + var mediumList = KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.communicationMediumCampaign(), "COMMRESTRICTION.MEDIUM"); + var mask = new SqlMaskingUtils() var orgContactSubselect = newSelect("orgContact.CONTACTID") .from("CONTACT anyContact") @@ -539,20 +537,19 @@ ContactUtils.getActiveCommRestrictionsSubselect = function() .and("orgContact.PERSON_ID IS NULL")) .where("anyContact.CONTACTID = CONTACT.CONTACTID") - mediumList.forEach(function(pMedium) + var group = mask.getGroupConcat("DISTINCT "+mediumList, "', '"); + var subselect = "''"; + if(group) { - var subquery = newSelect("COMMRESTRICTION.MEDIUM, COMMRESTRICTIONID") - .from("COMMRESTRICTION") - .where("COMMRESTRICTION.MEDIUM", pMedium[0]) - .and("COMMRESTRICTION.STARTDATE", vars.get("$sys.date"), SqlBuilder.LESS_OR_EQUAL()) - .and(newWhere() - .or("COMMRESTRICTION.CONTACT_ID = CONTACT.CONTACTID") - .or("COMMRESTRICTION.CONTACT_ID", orgContactSubselect)); - //!SqlBuilder - parts.push("case when exists(" + subquery.toString() + ") then '" + pMedium[1] + "' else '' end"); - }) - - return sqlMasking.concatWithSeparator(parts, " ", false); + var res = newSelect(group).from("COMMRESTRICTION") + .where("COMMRESTRICTION.CONTACT_ID = CONTACT.CONTACTID") + + var subres = newSelect(group).from("COMMRESTRICTION") + .where("COMMRESTRICTION.CONTACT_ID in ( "+orgContactSubselect.toString()+")") + + subselect = mask.concatWithSeparator(["("+res.toString()+")", "("+subres.toString()+")"], ", ", false); + } + return subselect; } /** diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js index eecd2a9c83..8c981ecd4d 100644 --- a/process/Sql_lib/process.js +++ b/process/Sql_lib/process.js @@ -3292,6 +3292,45 @@ SqlMaskingUtils.prototype.getConcatSymbol = function() } } + +/** +* Returns the group_concat function, which groups <br> +* multiple Row Values into one Cell. Note: This function <br> +* does not work on Derby<br> +* +* @param {String} pField <p> +* Expression that shall be grouped.<br> +* @param {String} pSeperator <p> +* Character that shall be used as Seperator<br> +* @return {String} <p> +* Returns the field with groupConcat wrapped around<br> +*/ +SqlMaskingUtils.prototype.getGroupConcat = function(pField, pSeperator) +{ + var group; + if(pField == null || pSeperator == null || pField == null && pSeperator == null) + throw new Error(translate.withArguments("Field or Seperator were empty function: %0", ["SqlMaskingUtils.prototype.getGroupConcat"])); + + switch(this.dbType) + { + case db.DBTYPE_MARIADB10: + case db.DBTYPE_MYSQL4: + group = " GROUP_CONCAT("+pField+" SEPARATOR "+pSeperator+")"; + break; + case db.DBTYPE_ORACLE10_CLUSTER: + case db.DBTYPE_ORACLE10_THIN: + case db.DBTYPE_ORACLE10_OCI: + case db.DBTYPE_POSTGRESQL8: + case db.DBTYPE_SQLSERVER2000: + group = " STRING_AGG("+pField+", "+pSeperator+")"; + break; + case db.DBTYPE_DERBY10: + logging.log(translate.withArguments("${SQL_LIB_UNSUPPORTED_DBTYPE} function: %0", ["SqlMaskingUtils.prototype.getGroupConcat"]), logging.ERROR); + break; + } + return group; +} + /** * Returns the trim function, which removes the<br> * leading and trailing spaces in a string, depending<br> -- GitLab