couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject [2/2] git commit: Add view request duration to Futon
Date Sat, 05 Nov 2011 15:07:20 GMT
Add view request duration to Futon

Closes COUCHDB-509


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/2d2c7d1e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/2d2c7d1e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/2d2c7d1e

Branch: refs/heads/master
Commit: 2d2c7d1ef49e3e051daf9ee0ea60896a493073fb
Parents: 2190ff0
Author: Filipe David Borba Manana <fdmanana@apache.org>
Authored: Sat Nov 5 14:55:55 2011 +0000
Committer: Filipe David Borba Manana <fdmanana@apache.org>
Committed: Sat Nov 5 15:06:47 2011 +0000

----------------------------------------------------------------------
 share/www/database.html          |    3 ++
 share/www/script/futon.browse.js |   39 ++++++++++++++++++++++++++++++++-
 share/www/script/jquery.couch.js |   11 ++++++---
 share/www/style/layout.css       |    2 +
 4 files changed, 50 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/2d2c7d1e/share/www/database.html
----------------------------------------------------------------------
diff --git a/share/www/database.html b/share/www/database.html
index 213159b..7a3294f 100644
--- a/share/www/database.html
+++ b/share/www/database.html
@@ -262,6 +262,9 @@ specific language governing permissions and limitations under the License.
           </tr>
         </tbody>
       </table>
+      <p id="viewrequestduration">
+        View request duration: <span class="timestamp"></span>
+      </p>
     </div>
   </div></body>
 </html>

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2d2c7d1e/share/www/script/futon.browse.js
----------------------------------------------------------------------
diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js
index b24840e..d336237 100644
--- a/share/www/script/futon.browse.js
+++ b/share/www/script/futon.browse.js
@@ -11,6 +11,38 @@
 // the License.
 
 (function($) {
+
+  $.toTimeString = function(milliseconds) {
+    var ms, sec, min, h, timeString;
+
+    sec = Math.floor(milliseconds / 1000.0);
+    min = Math.floor(sec / 60.0);
+    sec = (sec % 60.0).toString();
+    if (sec.length < 2) {
+       sec = "0" + sec;
+    }
+
+    h = (Math.floor(min / 60.0)).toString();
+    if (h.length < 2) {
+      h = "0" + h;
+    }
+
+    min = (min % 60.0).toString();
+    if (min.length < 2) {
+      min = "0" + min;
+    }
+
+    timeString = h + ":" + min + ":" + sec;
+
+    ms = (milliseconds % 1000.0).toString();
+    while (ms.length < 3) {
+      ms = "0" + ms;
+    }
+    timeString += "." + ms;
+
+    return timeString;
+  };
+
   $.futon = $.futon || {};
   $.extend($.futon, {
 
@@ -624,7 +656,7 @@
         $("#documents").find("tbody.content").empty().end().show();
         page.updateDesignDocLink();
 
-        options.success = function(resp) {
+        options.success = function(resp, requestDuration) {
           if (resp.offset === undefined) {
             resp.offset = 0;
           }
@@ -734,6 +766,11 @@
             "Showing " + firstNum + "-" + lastNum + " of " + totalNum +
             " row" + (firstNum != lastNum || totalNum == "unknown" ? "s" : ""));
           $("#documents tbody tr:odd").addClass("odd");
+
+          if (viewName && viewName !== "_all_docs" && viewName !== "_design_docs")
{
+            $("#viewrequestduration").show();
+            $("#viewrequestduration .timestamp").text($.toTimeString(requestDuration));
+          }
         }
         options.error = function(status, error, reason) {
           alert("Error: " + error + "\n\n" + reason);

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2d2c7d1e/share/www/script/jquery.couch.js
----------------------------------------------------------------------
diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js
index 2c4c89e..4ae3d40 100644
--- a/share/www/script/jquery.couch.js
+++ b/share/www/script/jquery.couch.js
@@ -1005,7 +1005,7 @@
    * @private
    */
   function ajax(obj, options, errorMessage, ajaxOptions) {
-
+    var timeStart;
     var defaultAjaxOpts = {
       contentType: "application/json",
       headers:{"Accept": "application/json"}
@@ -1014,6 +1014,7 @@
     options = $.extend({successStatus: 200}, options);
     ajaxOptions = $.extend(defaultAjaxOpts, ajaxOptions);
     errorMessage = errorMessage || "Unknown error";
+    timeStart = (new Date()).getTime();
     $.ajax($.extend($.extend({
       type: "GET", dataType: "json", cache : !$.browser.msie,
       beforeSend: function(xhr){
@@ -1024,6 +1025,7 @@
         }
       },
       complete: function(req) {
+        var reqDuration = (new Date()).getTime() - timeStart;
         try {
           var resp = $.parseJSON(req.responseText);
         } catch(e) {
@@ -1038,11 +1040,12 @@
           options.ajaxStart(resp);
         }
         if (req.status == options.successStatus) {
-          if (options.beforeSuccess) options.beforeSuccess(req, resp);
-          if (options.success) options.success(resp);
+          if (options.beforeSuccess) options.beforeSuccess(req, resp, reqDuration);
+          if (options.success) options.success(resp, reqDuration);
         } else if (options.error) {
           options.error(req.status, resp && resp.error ||
-                        errorMessage, resp && resp.reason || "no response");
+                        errorMessage, resp && resp.reason || "no response",
+                        reqDuration);
         } else {
           alert(errorMessage + ": " + resp.reason);
         }

http://git-wip-us.apache.org/repos/asf/couchdb/blob/2d2c7d1e/share/www/style/layout.css
----------------------------------------------------------------------
diff --git a/share/www/style/layout.css b/share/www/style/layout.css
index ea8b117..814eecd 100644
--- a/share/www/style/layout.css
+++ b/share/www/style/layout.css
@@ -387,6 +387,8 @@ body.loading #dialog h2 {
 
 #tempwarn { display: none; font-size: 90%; margin: 0 2em 1.5em; }
 #grouptruenotice { display: none; font-size: 90%; margin: 1ex 2em 1.5em; }
+#viewrequestduration { display: none; font-size: 90%; margin: 1ex 2em 1.5em; }
+#viewrequestduration .timestamp { margin-left: 0.25em; }
 
 /* Database table */
 


Mime
View raw message