On Sat, Jun 20, 2009 at 6:50 PM, Gene Amtower <[email protected]> wrote:

>  Derrell,
>
> I just saw the new snippet in "The week in qooxdoo (2009-06-19)" on
> avoiding excessive server calls when using the Remote Table Model, and I
> applied it to my Remote Table Model implementation code.  Actually, I
> wondered why Qooxdoo made multiple calls to the backend each time my
> application updated the remote table, and this solved the issue.  It works
> like a charm and speeds things up considerably by avoiding repetitive table
> updates.
>
> Will you be making a similar update to RpcExample in the contrib section so
> that users who implement this for the first time by copying RpcExample
> include this enhancement?  I can't imagine any reason to not have this
> feature coded as standard practice for any Remote Table Model
> implementation, but maybe you know of a good reason.
>

Hi Gene,

So, /me starts thinking (a dangerous thing, I know)... If this snippet shows
a good general procedure, then how about if we fix it in the remote table
model instead of having to kludge it in each application? Would you please
try reverting your changes which were a result of seeing that snippet and
applying the attached patch to qx.ui.table.model.Remote. This should fix the
problem at the proper level. (Of course, the real proper solution is to
redesign the table so that it doesn't need to issue so many loadRowCount()
requests... but that's a much bigger job not currently scheduled.)

Derrell
diff --git a/qooxdoo/framework/source/class/qx/ui/table/model/Remote.js b/qooxdoo/framework/source/class/qx/ui/table/model/Remote.js
index d403c9d..50d750d 100644
--- a/qooxdoo/framework/source/class/qx/ui/table/model/Remote.js
+++ b/qooxdoo/framework/source/class/qx/ui/table/model/Remote.js
@@ -109,6 +109,27 @@ qx.Class.define("qx.ui.table.model.Remote",
     {
       check : "Boolean",
       init : false
+    },
+
+    /*
+     * Whether to block remote requests for the row count while a request for
+     * the row count is pending. Row counts are requested at various times and
+     * from various parts of the code, resulting in numerous requests to the
+     * user-provided _loadRowCount() method, often while other requests are
+     * already pending. The default behavior now ignores requests to load a
+     * new row count if such a request is already pending. It is therefore now
+     * conceivable that the row count changes between an initial request for
+     * the row count and a later (ignored) request. Since the chance of this
+     * is low, the desirability of reducing the server requests outweighs the
+     * slight possibility of an altered count (which will, by the way, be
+     * detected soon thereafter upon the next request for the row count). If
+     * the old behavior is desired, set this property to false.
+     *
+     */
+    blockConcurrentLoadRowCount:
+    {
+      check : "Boolean",
+      init  : true
     }
   },
 
@@ -139,13 +160,18 @@ qx.Class.define("qx.ui.table.model.Remote",
     __editableColArr : null,
     __sortableColArr : null,
 
+    __loadRowCountRequestRunning : false,
 
     // overridden
     getRowCount : function()
     {
       if (this.__rowCount == -1)
       {
-        this._loadRowCount();
+        if (! this.__loadRowCountRequestRunning ||
+            ! this.getBlockConcurrentLoadRowCount())
+        {
+          this._loadRowCount();
+        }
 
         // NOTE: _loadRowCount may set this.__rowCount
         return (this.__rowCount == -1) ? 0 : this.__rowCount;
@@ -181,6 +207,12 @@ qx.Class.define("qx.ui.table.model.Remote",
      */
     _onRowCountLoaded : function(rowCount)
     {
+      if (this.getBlockConcurrentLoadRowCount())
+      {
+        // There's no longer a loadRowCount() in progress
+        this.__loadRowCountRequestRunning = false;
+      }
+
       // this.debug("row count loaded: " + rowCount);
       if (rowCount == null || rowCount < 0) {
         rowCount = 0;
@@ -230,7 +262,11 @@ qx.Class.define("qx.ui.table.model.Remote",
       this.__lastRowToLoad = -1;
 
       // NOTE: This will inform the listeners as soon as the new row count is known
-      this._loadRowCount();
+      if (! this.__loadRowCountRequestRunning ||
+          ! this.getBlockConcurrentLoadRowCount())
+      {
+        this._loadRowCount();
+      }
     },
 
 
------------------------------------------------------------------------------
Are you an open source citizen? Join us for the Open Source Bridge conference!
Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250.
Need another reason to go? 24-hour hacker lounge. Register today!
http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to