send proper response for zero-result queries
authorMike Shaver <shaver@mozilla.org>
Sun, 31 Oct 2010 04:30:47 +0000
changeset 3 080151f0344c2d04f6b086a048f968a00e435c46
parent 2 4dc435d1e3393f0687a7b094e8c47371d3aae65e
child 4 820d0888252f8ec9d0f6298dd8ecf19b334bb41b
push id4
push usershaver@mozilla.com
push dateSun, 31 Oct 2010 04:32:31 +0000
send proper response for zero-result queries
server/entry.html
server/websocket.js
--- a/server/entry.html
+++ b/server/entry.html
@@ -32,17 +32,17 @@ var results;
       var msg = $("#keywords").val();
       conn.sendTime = Date.now();
       conn.send(msg);
     }
   };
 
   $("#keywords").bind("keydown", function(e){
 
-if(e.keyCode == 32 || e.keyCode == 13)
+ if(e.keyCode == 32 || e.keyCode == 13)
 {
       sendmsg();
     }
   })
 
   function log(data){
     $("#matchingbugs").html(data);
   };
--- a/server/websocket.js
+++ b/server/websocket.js
@@ -23,21 +23,29 @@ function runSearch(message, conn)
     var startTime = Date.now();
     redisConn.sinter(words.map(function (v) { return "word:" + v;}),
 		     function (err, results) {
 			 if (err) {
 			     util.puts("ERR (redis): " + err);
 			     return;
 			 }
 
-			 if (!results)
-			     return;
-			 
 			 var resultmsg = { bugs: [] };
 
+			 if (!results) {
+			     var now = Date.now();
+			     resultmsg.times = { redis: now - startTime,
+						 server: now - conn.startTime };
+			     // console.log(JSON.stringify(resultmsg));
+			     conn.send(JSON.stringify(resultmsg));
+			     util.puts(conn.id + ": search " + words.length + " -> " + resultmsg.bugs.length + " in " +
+				       resultmsg.times.redis+ "/" + resultmsg.times.server + " ms");
+			     return;
+			 }
+		     
 			 var MAX_RESULTS = 100;
 			 var limit;
 			 if (results.length > MAX_RESULTS) {
 			     limit = MAX_RESULTS;
 			     resultmsg.hasMore = true;
 			     resultmsg.totalResults = results.length;
 			 } else {
 			     limit = results.length;