fixed bug 27632: unneeded DB queries + request in Query List Widget
authorAsier Lostalé <asier.lostale@openbravo.com>
Thu, 25 Sep 2014 12:17:25 +0200
changeset 24074 f192265ffb04
parent 24073 2eb08cb9faab
child 24075 e33eb7ed352a
fixed bug 27632: unneeded DB queries + request in Query List Widget

* Preventing extra request to get actual count of total number of records which
is potentially non-perfomant: now a hint of having more records is shown but
it doesn't include the total number
* Removed unneeded count in the request to get the actual data. This count caused
and extra DB query and the number got in that one was incorrect as it was always
the retrived number of records
modules/org.openbravo.client.querylist/src-db/database/sourcedata/AD_MESSAGE.xml
modules/org.openbravo.client.querylist/web/org.openbravo.client.querylist/js/ob-querylist-widget.js
--- a/modules/org.openbravo.client.querylist/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Sep 09 09:10:32 2014 +0200
+++ b/modules/org.openbravo.client.querylist/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Sep 25 12:17:25 2014 +0200
@@ -6,7 +6,7 @@
 <!--18EE399F2AF54EA3BEB5086D4BF6D4B1-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--18EE399F2AF54EA3BEB5086D4BF6D4B1-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--18EE399F2AF54EA3BEB5086D4BF6D4B1-->  <VALUE><![CDATA[OBCQL_RowsNumber]]></VALUE>
-<!--18EE399F2AF54EA3BEB5086D4BF6D4B1-->  <MSGTEXT><![CDATA[Showing %0 of %1 rows]]></MSGTEXT>
+<!--18EE399F2AF54EA3BEB5086D4BF6D4B1-->  <MSGTEXT><![CDATA[Showing %0 of many rows]]></MSGTEXT>
 <!--18EE399F2AF54EA3BEB5086D4BF6D4B1-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
 <!--18EE399F2AF54EA3BEB5086D4BF6D4B1-->  <AD_MODULE_ID><![CDATA[0A060B2AF1974E8EAA8DB61388E9AECC]]></AD_MODULE_ID>
 <!--18EE399F2AF54EA3BEB5086D4BF6D4B1-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
--- a/modules/org.openbravo.client.querylist/web/org.openbravo.client.querylist/js/ob-querylist-widget.js	Tue Sep 09 09:10:32 2014 +0200
+++ b/modules/org.openbravo.client.querylist/web/org.openbravo.client.querylist/js/ob-querylist-widget.js	Thu Sep 25 12:17:25 2014 +0200
@@ -182,19 +182,24 @@
   },
 
   setTotalRows: function (totalRows) {
+    // totalRows is the total number of rows retrieved from backend, in order to
+    // improve performance count of actual number of records is not performed, so
+    // we can only give a hint about having more items in case it is equal to the
+    // rows num parameter
     this.totalRows = totalRows;
     if (this.viewMode === 'maximized') {
-      this.setTitle(this.widgetTitle + " (" + this.totalRows + ")");
       this.showAllLabel.hide();
       return;
     }
-    if (this.showAllLabel.getMembers()[0]) {
-      this.showAllLabel.getMembers()[0].setContents(
-      OB.I18N.getLabel('OBCQL_RowsNumber', [this.parameters.RowsNumber, this.totalRows]));
-    }
-    if (this.parameters.showAll || this.totalRows <= this.parameters.RowsNumber) {
+
+    if (this.parameters.showAll || this.totalRows < this.parameters.RowsNumber) {
+      // if showing pagination or all the records, hide the label
       this.showAllLabel.hide();
     } else {
+      if (this.showAllLabel.getMembers()[0]) {
+        this.showAllLabel.getMembers()[0].setContents(
+        OB.I18N.getLabel('OBCQL_RowsNumber', [this.parameters.RowsNumber]));
+      }
       this.showAllLabel.show();
     }
     this.setWidgetHeight();
@@ -220,6 +225,9 @@
   canAutoFitFields: false,
   showGridSummary: true,
 
+  // prevent multiple requests for 1st page
+  drawAllMaxCells: 0,
+
   summaryRowProperties: {
     showEmptyMessage: false
   },
@@ -288,6 +296,9 @@
     params.viewMode = this.widget.viewMode;
     params.showAll = this.widget.parameters.showAll;
     params.UTCOffsetMiliseconds = OB.Utilities.Date.getUTCOffsetInMiliseconds();
+
+    // prevent the count operation
+    params[isc.OBViewGrid.NO_COUNT_PARAMETER] = 'true';
     return params;
   },
 
@@ -337,10 +348,8 @@
       requestProperties.params.showAll = true;
       // sometimes we get here before the datasource
       // is set
-      if (this.dataSource) {
-        this.dataSource.fetchData(criteria, function (dsResponse, data, dsRequest) {
-          dsResponse.clientContext.grid.widget.setTotalRows(dsResponse.totalRows);
-        }, requestProperties);
+      if (dsResponse) {
+        this.widget.setTotalRows(dsResponse.totalRows);
       }
     } else {
       this.widget.setTotalRows(dsResponse.totalRows);