From 8e8a0b04544d6ef1c66f2b80489fba3bd6d0c32c Mon Sep 17 00:00:00 2001
From: "b.ulrich" <b.ulrich@adito.de>
Date: Thu, 30 Sep 2021 14:23:30 +0200
Subject: [PATCH] [Projekt: xRM-Sales][TicketNr.: 2001102][Salesproject
 performance wegen checklisten schlecht]

---
 .../ChecklistEntryValue_entity.aod            |   6 ++
 .../presentationmode_param/documentation.adoc |   5 +
 .../recordcontainers/jdito/contentProcess.js  | 101 +++++++++---------
 .../recordcontainers/jdito/rowCountProcess.js |  20 ++++
 .../Organisation_entity.aod                   |   4 +
 .../presentationmode_param/valueProcess.js    |   4 +
 .../Salesproject_entity.aod                   |   4 +
 .../presentationmode_param/valueProcess.js    |   4 +
 8 files changed, 99 insertions(+), 49 deletions(-)
 create mode 100644 entity/ChecklistEntryValue_entity/entityfields/presentationmode_param/documentation.adoc
 create mode 100644 entity/ChecklistEntryValue_entity/recordcontainers/jdito/rowCountProcess.js
 create mode 100644 entity/Organisation_entity/entityfields/checklistentryvalues/children/presentationmode_param/valueProcess.js
 create mode 100644 entity/Salesproject_entity/entityfields/checklistentryvalues/children/presentationmode_param/valueProcess.js

diff --git a/entity/ChecklistEntryValue_entity/ChecklistEntryValue_entity.aod b/entity/ChecklistEntryValue_entity/ChecklistEntryValue_entity.aod
index e61fa7ee53..2eb878e8a5 100644
--- a/entity/ChecklistEntryValue_entity/ChecklistEntryValue_entity.aod
+++ b/entity/ChecklistEntryValue_entity/ChecklistEntryValue_entity.aod
@@ -107,12 +107,18 @@
       <title>Fullfilled</title>
       <contentType>IMAGE</contentType>
     </entityField>
+    <entityParameter>
+      <name>Presentationmode_param</name>
+      <expose v="true" />
+      <documentation>%aditoprj%/entity/ChecklistEntryValue_entity/entityfields/presentationmode_param/documentation.adoc</documentation>
+    </entityParameter>
   </entityFields>
   <recordContainers>
     <jDitoRecordContainer>
       <name>jDito</name>
       <jDitoRecordAlias>Data_alias</jDitoRecordAlias>
       <contentProcess>%aditoprj%/entity/ChecklistEntryValue_entity/recordcontainers/jdito/contentProcess.js</contentProcess>
+      <rowCountProcess>%aditoprj%/entity/ChecklistEntryValue_entity/recordcontainers/jdito/rowCountProcess.js</rowCountProcess>
       <recordFieldMappings>
         <jDitoRecordFieldMapping>
           <name>UID.value</name>
diff --git a/entity/ChecklistEntryValue_entity/entityfields/presentationmode_param/documentation.adoc b/entity/ChecklistEntryValue_entity/entityfields/presentationmode_param/documentation.adoc
new file mode 100644
index 0000000000..815090a034
--- /dev/null
+++ b/entity/ChecklistEntryValue_entity/entityfields/presentationmode_param/documentation.adoc
@@ -0,0 +1,5 @@
+== Presentationmode_param
+
+This param is getting used by the entities that are displaying the checklist in their mainview. 
+They are returning their sys.presentationmode so we can use it in our contentProcess to check whether or not we are in the mainview to only then load the checklistEntryValues.
+Currently it's not possible to check for the sys.presentationmode in here since it always returns null.
\ No newline at end of file
diff --git a/entity/ChecklistEntryValue_entity/recordcontainers/jdito/contentProcess.js b/entity/ChecklistEntryValue_entity/recordcontainers/jdito/contentProcess.js
index 023eef2771..d8dfabcf2b 100644
--- a/entity/ChecklistEntryValue_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/ChecklistEntryValue_entity/recordcontainers/jdito/contentProcess.js
@@ -7,60 +7,63 @@ import("system.datetime");
 import("Sql_lib");
 import("ChecklistEntryRegistry_basic");
 
-var checklistIds = JSON.parse(vars.get("$param.ChecklistIds_param"));
+var data = [];
+if(vars.get("$param.Presentationmode_param") == "FULL")
+{
+    var checklistIds = JSON.parse(vars.get("$param.ChecklistIds_param"));
 
-var data = newSelect([
-    "CHECKLISTENTRYVALUE.CHECKLISTENTRYVALUEID",
-    "CHECKLISTENTRY.AUTO",
-    "CHECKLISTENTRY.CHECKLISTENTRYID",
-    "CHECKLISTENTRY.TITLE",
-    "CHECKLISTENTRY.FILTER_USED",
-    "CHECKLISTENTRY.COND",
-    "CHECKLISTENTRYVALUE.DONEUSER",
-    "CHECKLISTENTRYVALUE.DONEDATE",
-    "CHECKLISTENTRYVALUE.IS_FULFILLED",
-    "CHECKLISTENTRYVALUE.OBJECT_ROWID",
-    "CHECKLISTENTRYVALUE.OBJECT_TYPE",
-    "CHECKLISTENTRYVALUE.DATE_EDIT",
-    "CHECKLISTENTRYVALUE.DATE_NEW",
-    "CHECKLISTENTRYVALUE.USER_EDIT",
-    "CHECKLISTENTRYVALUE.USER_NEW"
-]).from("CHECKLISTENTRY")
-.leftJoin(
-    "CHECKLISTENTRYVALUE",
-    newWhere("CHECKLISTENTRYVALUE.CHECKLISTENTRY_ID = CHECKLISTENTRY.CHECKLISTENTRYID")
-    .and("CHECKLISTENTRYVALUE.OBJECT_ROWID", vars.get("$param.ObjectRowId_param"))
-    .andIfSet("CHECKLISTENTRYVALUE.OBJECT_TYPE", vars.get("$param.ObjectType_param"))
-).whereIfSet("CHECKLISTENTRY.CHECKLIST_ID", checklistIds, SqlBuilder.IN())
-.orderBy("CHECKLISTENTRY.POS asc")
-.table();
+    data = newSelect([
+        "CHECKLISTENTRYVALUE.CHECKLISTENTRYVALUEID",
+        "CHECKLISTENTRY.AUTO",
+        "CHECKLISTENTRY.CHECKLISTENTRYID",
+        "CHECKLISTENTRY.TITLE",
+        "CHECKLISTENTRY.FILTER_USED",
+        "CHECKLISTENTRY.COND",
+        "CHECKLISTENTRYVALUE.DONEUSER",
+        "CHECKLISTENTRYVALUE.DONEDATE",
+        "CHECKLISTENTRYVALUE.IS_FULFILLED",
+        "CHECKLISTENTRYVALUE.OBJECT_ROWID",
+        "CHECKLISTENTRYVALUE.OBJECT_TYPE",
+        "CHECKLISTENTRYVALUE.DATE_EDIT",
+        "CHECKLISTENTRYVALUE.DATE_NEW",
+        "CHECKLISTENTRYVALUE.USER_EDIT",
+        "CHECKLISTENTRYVALUE.USER_NEW"
+    ]).from("CHECKLISTENTRY")
+    .leftJoin(
+        "CHECKLISTENTRYVALUE",
+        newWhere("CHECKLISTENTRYVALUE.CHECKLISTENTRY_ID = CHECKLISTENTRY.CHECKLISTENTRYID")
+        .and("CHECKLISTENTRYVALUE.OBJECT_ROWID", vars.get("$param.ObjectRowId_param"))
+        .andIfSet("CHECKLISTENTRYVALUE.OBJECT_TYPE", vars.get("$param.ObjectType_param"))
+    ).whereIfSet("CHECKLISTENTRY.CHECKLIST_ID", checklistIds, SqlBuilder.IN())
+    .orderBy("CHECKLISTENTRY.POS asc")
+    .table();
 
-for(let i = 0; i < data.length; i++)
-{
-    data[i][0] = data[i][0] || util.getNewUUID();
-    data[i][3] = translate.text(data[i][3]);
-    data[i][8] = data[i][8] || "0";
-    data[i][9] = data[i][9] || vars.get("$param.ObjectRowId_param");
-    data[i][10] = data[i][10] || vars.get("$param.ObjectType_param");
-    data[i][12] = data[i][12] || datetime.date();
-    data[i][14] = data[i][14] || vars.get("$sys.user");
-    
-    if(parseInt(data[i][1]))
+    for(let i = 0; i < data.length; i++)
     {
-        var checklistEntry;
-        if (Utils.toBoolean(data[i][4])) // FILTER_USED
-        {
-            checklistEntry = $ChecklistEntryRegistry["filter"]();
-            data[i][8] = checklistEntry.verifierFn(vars.get("$param.ObjectRowId_param"), vars.get("$param.ObjectType_param"), data[i][5]) ? "1" : "0";
-        }
-        else
+        data[i][0] = data[i][0] || util.getNewUUID();
+        data[i][3] = translate.text(data[i][3]);
+        data[i][8] = data[i][8] || "0";
+        data[i][9] = data[i][9] || vars.get("$param.ObjectRowId_param");
+        data[i][10] = data[i][10] || vars.get("$param.ObjectType_param");
+        data[i][12] = data[i][12] || datetime.date();
+        data[i][14] = data[i][14] || vars.get("$sys.user");
+
+        if(parseInt(data[i][1]))
         {
-            checklistEntry = $ChecklistEntryRegistry[data[i][3]]();
-            data[i][8] = checklistEntry.verifierFn(vars.get("$param.ObjectRowId_param")) ? "1" : "0";
-            data[i][3] = checklistEntry.title;
+            var checklistEntry;
+            if (Utils.toBoolean(data[i][4])) // FILTER_USED
+            {
+                checklistEntry = $ChecklistEntryRegistry["filter"]();
+                data[i][8] = checklistEntry.verifierFn(vars.get("$param.ObjectRowId_param"), vars.get("$param.ObjectType_param"), data[i][5]) ? "1" : "0";
+            }
+            else
+            {
+                checklistEntry = $ChecklistEntryRegistry[data[i][3]]();
+                data[i][8] = checklistEntry.verifierFn(vars.get("$param.ObjectRowId_param")) ? "1" : "0";
+                data[i][3] = checklistEntry.title;
+            }
         }
+        data[i][15] = Utils.toBoolean(data[i][8]) ? "NEON:MQL" : ""; //icon
     }
-    data[i][15] = Utils.toBoolean(data[i][8]) ? "NEON:MQL" : ""; //icon
 }
-
 result.object(data);
diff --git a/entity/ChecklistEntryValue_entity/recordcontainers/jdito/rowCountProcess.js b/entity/ChecklistEntryValue_entity/recordcontainers/jdito/rowCountProcess.js
new file mode 100644
index 0000000000..f4f77893f4
--- /dev/null
+++ b/entity/ChecklistEntryValue_entity/recordcontainers/jdito/rowCountProcess.js
@@ -0,0 +1,20 @@
+import("system.result");
+import("Sql_lib");
+import("system.vars");
+
+var data = [];
+if(vars.get("$param.Presentationmode_param") == "FULL")
+{
+    var checklistIds = JSON.parse(vars.get("$param.ChecklistIds_param"));
+
+    data = newSelect("1")
+    .from("CHECKLISTENTRY")
+    .leftJoin(
+        "CHECKLISTENTRYVALUE",
+        newWhere("CHECKLISTENTRYVALUE.CHECKLISTENTRY_ID = CHECKLISTENTRY.CHECKLISTENTRYID")
+        .and("CHECKLISTENTRYVALUE.OBJECT_ROWID", vars.get("$param.ObjectRowId_param"))
+        .andIfSet("CHECKLISTENTRYVALUE.OBJECT_TYPE", vars.get("$param.ObjectType_param"))
+    ).whereIfSet("CHECKLISTENTRY.CHECKLIST_ID", checklistIds, SqlBuilder.IN())
+    .table();
+}
+result.object(data.length);
\ No newline at end of file
diff --git a/entity/Organisation_entity/Organisation_entity.aod b/entity/Organisation_entity/Organisation_entity.aod
index 72cb6cdb2b..6d533c314c 100644
--- a/entity/Organisation_entity/Organisation_entity.aod
+++ b/entity/Organisation_entity/Organisation_entity.aod
@@ -1409,6 +1409,10 @@
           <name>ChecklistIds_param</name>
           <valueProcess>%aditoprj%/entity/Organisation_entity/entityfields/checklistentryvalues/children/checklistids_param/valueProcess.js</valueProcess>
         </entityParameter>
+        <entityParameter>
+          <name>Presentationmode_param</name>
+          <valueProcess>%aditoprj%/entity/Organisation_entity/entityfields/checklistentryvalues/children/presentationmode_param/valueProcess.js</valueProcess>
+        </entityParameter>
       </children>
     </entityConsumer>
     <entityParameter>
diff --git a/entity/Organisation_entity/entityfields/checklistentryvalues/children/presentationmode_param/valueProcess.js b/entity/Organisation_entity/entityfields/checklistentryvalues/children/presentationmode_param/valueProcess.js
new file mode 100644
index 0000000000..c5f4daf649
--- /dev/null
+++ b/entity/Organisation_entity/entityfields/checklistentryvalues/children/presentationmode_param/valueProcess.js
@@ -0,0 +1,4 @@
+import("system.vars");
+import("system.result");
+
+result.string(vars.get("$sys.presentationmode"));
\ No newline at end of file
diff --git a/entity/Salesproject_entity/Salesproject_entity.aod b/entity/Salesproject_entity/Salesproject_entity.aod
index 970e68b2e4..3c4f32e16e 100644
--- a/entity/Salesproject_entity/Salesproject_entity.aod
+++ b/entity/Salesproject_entity/Salesproject_entity.aod
@@ -726,6 +726,10 @@
           <name>ChecklistIds_param</name>
           <valueProcess>%aditoprj%/entity/Salesproject_entity/entityfields/checklistentryvalues/children/checklistids_param/valueProcess.js</valueProcess>
         </entityParameter>
+        <entityParameter>
+          <name>Presentationmode_param</name>
+          <valueProcess>%aditoprj%/entity/Salesproject_entity/entityfields/checklistentryvalues/children/presentationmode_param/valueProcess.js</valueProcess>
+        </entityParameter>
       </children>
     </entityConsumer>
     <entityParameter>
diff --git a/entity/Salesproject_entity/entityfields/checklistentryvalues/children/presentationmode_param/valueProcess.js b/entity/Salesproject_entity/entityfields/checklistentryvalues/children/presentationmode_param/valueProcess.js
new file mode 100644
index 0000000000..c5f4daf649
--- /dev/null
+++ b/entity/Salesproject_entity/entityfields/checklistentryvalues/children/presentationmode_param/valueProcess.js
@@ -0,0 +1,4 @@
+import("system.vars");
+import("system.result");
+
+result.string(vars.get("$sys.presentationmode"));
\ No newline at end of file
-- 
GitLab