let client do timing math (refactoring prep)
authorMike Shaver <shaver@mozilla.org>
Fri, 18 Feb 2011 00:57:56 +0000
changeset 46 81a637791dcf
parent 45 9f5840f3a1b0
child 47 27f72a12a0f4
push id35
push usershaver@mozilla.com
push dateFri, 18 Feb 2011 01:00:06 +0000
let client do timing math (refactoring prep)
server/static/search.js
server/websocket.js
--- a/server/static/search.js
+++ b/server/static/search.js
@@ -12,18 +12,19 @@ var results;
 
     var xhr = new XMLHttpRequest();
     xhr.open("GET", "/search?" + encodeURI(terms), true);
     xhr.onreadystatechange = function() {
         if (xhr.readyState != 4 || xhr.status != 200)
             return;
         var results = JSON.parse(xhr.responseText);
         var div = $("#matchingbugs");
+        var t = results.times;
         div.html(results.bugs.length + " results for '" + $("#keywords").val() + "' in " +  (Date.now() - xhr.sendTime) + " (total)/" +
-                 results.times.server + " (server)/" + results.times.redis + " (redis) ms<br><i>Shift-click words to refine search</i><br>");
+                 (t.finishTime - t.startTime) + " (server)/" + (t.finishTime - t.redisStart) + " (redis) ms<br><i>Shift-click words to refine search</i><br>");
 
         results.bugs.forEach(function (v) { div.append("<a href='https://bugzilla.mozilla.org/show_bug.cgi?id=" + v.id + "'>" + v.id + "</a>: ");
         div.append(document.createTextNode(v.summary)); div.append("<br>"); });
         if (results.hasMore)
             div.append("<br>(Showing " + results.bugs.length + " of " + results.totalResults + " results)<br>");
         };
     xhr.sendTime = Date.now();
     xhr.send(null);
--- a/server/websocket.js
+++ b/server/websocket.js
@@ -11,24 +11,23 @@ var redis = require('redis');
 var redisConn = redis.createClient();
 
 redisConn.on("error",  function (err) {
     util.log("Redis connection error to " + redisConn.host + ":" + redisConn.port + " - " + err);
 });
 
 function runSearch(message, cb)
 {
-
     var startTime = Date.now();
     var resultmsg = { bugs: [] };
 
     function sendResponse()
     {
         var now = Date.now();
-        resultmsg.times = { redis: (now - redisStartTime) || 0, server: now - startTime };
+        resultmsg.times = { startTime: startTime, redisStart: redisStartTime, finishTime: Date.now() };
 
         cb(JSON.stringify(resultmsg));
         util.log("search " + words.length + "/" + message + " -> " + (resultmsg.totalResults || resultmsg.bugs.length) + " in " +
                     resultmsg.times.redis+ "/" + resultmsg.times.server + " ms");
     }
 
     var words = indexer.keywordsForSummary(message);
     if (words.length == 0)