[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [atlas/master] Allow returning up to 50 search results and error on empty search



commit e520e51585dd1b6145cc44546b82ca521fe9bd03
Author: Iain R. Learmonth <irl@xxxxxxxxxx>
Date:   Sat Jun 11 14:00:33 2016 +0100

    Allow returning up to 50 search results and error on empty search
    
     * Added the ability for errors to be passed along when rendering result
       sets, to display an error or warning message while still allowing
       a result set to be rendered.
     * Results are only rendered once all the requests have succeeded (or
       failed), not every time there is a response. This greatly improves
       the performance and now up to 50 results can be rendered reasonably.
     * Limits the result set to a maximum of 50 results, introducing a new
       error message when this number is exceeded. (Fixes: #15395)
     * Introduces a new error message when an empty string is passed and
       fixed the rendering of that error message by displaying it. (Fixes:
       #19372)
     * Thanks to karsten and hellais for their help on this patch. (:
---
 js/collections/results.js | 27 +++++++++++++++++----------
 js/router.js              | 13 +++++++++----
 js/views/search/do.js     |  6 +++---
 templates/search/do.html  | 34 ++++++++++++++++++++++++++++------
 4 files changed, 57 insertions(+), 23 deletions(-)

diff --git a/js/collections/results.js b/js/collections/results.js
index e618614..4473e1a 100644
--- a/js/collections/results.js
+++ b/js/collections/results.js
@@ -12,6 +12,7 @@ define([
 		lookup: function(options) {
             var success = options.success;
             var error = options.error;
+            var err = 0;
             var collection = this;
             options.success = $.getJSON(this.url, function(response) {
                 this.fresh_until = response.fresh_until;
@@ -33,23 +34,29 @@ define([
                 });
                 if (relays.length == 0) {
                     error(0);
-                    console.log('error');
-                    return false;
-                } else if (relays.length > 40) {
-                    error(1);
+                    console.log('Empty result set was returned');
                     return false;
+                } else if (relays.length > 50) {
+		    relays = relays.slice(0, 50);
+		    err = 4;
+		    console.log(options);
                 }
+                var lookedUpRelays = 0;
                 _.each(relays, function(relay) {
+                    var lookedUp = function() {
+                      lookedUpRelays++;
+                      if (lookedUpRelays == relays.length) {
+                        success(err);
+                      }
+                    }
                     relay.lookup({
                         success: function(){
-                            if (relays.length == response.relays.length + response.bridges.length) {
-                                collection[options.add ? 'add' : 'reset'](relays, options);
-                                success(collection, relays);
-                                return relays;
-                            }
+                            collection[options.add ? 'add' : 'reset'](relays, options);
+                            lookedUp();
                         },
                         error: function() {
-                            console.log("error in loading..");
+                            console.log("error in loading one relay..");
+                            lookedUp();
                             error(0);
                         }
                     });
diff --git a/js/router.js b/js/router.js
index 92b2647..6513e19 100644
--- a/js/router.js
+++ b/js/router.js
@@ -61,21 +61,26 @@ define([
 
         $("#nav-search").val(query);
         if (query == "") {
-            doSearchView.error(0);
+            $("#content").show();
+	    doSearchView.error = 5;
+            doSearchView.renderError();
+            $("#loading").hide();
         } else {
             doSearchView.collection.url =
                 doSearchView.collection.baseurl + this.hashFingerprints(query);
             doSearchView.collection.lookup({
-                success: function(relays){
+                success: function(err){
                     $("#content").show();
                     doSearchView.relays = doSearchView.collection.models;
+		    doSearchView.error = err;
                     doSearchView.render(query);
                     $("#loading").hide();
                 },
 
-                error: function(erno){
+                error: function(err){
                     $("#content").show();
-                    doSearchView.error(erno);
+		    doSearchView.error = err;
+		    doSearchView.renderError();
                     $("#loading").hide();
                 }
             });
diff --git a/js/views/search/do.js b/js/views/search/do.js
index 5e077ec..64cb28d 100644
--- a/js/views/search/do.js
+++ b/js/views/search/do.js
@@ -148,7 +148,7 @@ define([
             document.title = "Atlas";
             this.filtering();
             var asInitVals = new Array();
-        	var compiledTemplate = _.template(doSearchTemplate, {relays: this.relays, countries: CountryCodes});
+		var compiledTemplate = _.template(doSearchTemplate, {relays: this.relays, countries: CountryCodes, error: this.error});
 			this.el.html(compiledTemplate);
 	    	$("#loading").hide();
 			var fp = this;
@@ -227,8 +227,8 @@ define([
 
         },
 
-	    error: function(err){
-	    	var compiledTemplate = _.template(doSearchTemplate, {relays: null, error: err});
+	    renderError: function(){
+	    	var compiledTemplate = _.template(doSearchTemplate, {relays: null, error: this.error, countries: null});
 	    	$("#loading").hide();
 	    	this.el.html(compiledTemplate);
 	    }
diff --git a/templates/search/do.html b/templates/search/do.html
index dfb0fc1..95fea6c 100644
--- a/templates/search/do.html
+++ b/templates/search/do.html
@@ -1,18 +1,18 @@
 <div class="results_box">
-<% if(!relays) {%>
-    <% if(error == 0) {%>
+<% if(!relays) { %>
+    <% if(error == 0) { %>
     <div class="alert">
         <strong>No Results found!</strong><p>
     No Tor relays matched your query :(</p>
     </div>
-    <% } else if (error == 1) {%>
+    <% } else if (error == 1) { %>
     <div class="alert alert-error">
         <strong>Too many matches!</strong><p>The current version of Atlas does
     not support a result set greater than 40. This is due to some performance
     issues in doing multiple parallel connections in javascript. Future versions
     will hopefully manage to overcome this issue.</p>
     </div>
-    <% } else if (error == 2) {%>
+    <% } else if (error == 2) { %>
     <div class="alert alert-error">
         <strong>Backend error!</strong>
         <p>Atlas is unable to get a response from its backend server. This
@@ -22,12 +22,34 @@
         page</a> that explains what type of search queries are supported by
         Atlas.</p>
     </div>
-    <% } else if (error == 3) {%>
+    <% } else if (error == 3) { %>
     <div class="alert alert-error">
-        <strong>JavaScript Error!</strong><p>There is a problem with your javascript environment, you may have noscript enabled on the remote onionoo backend. Try temporarily allowing noscript to connect to the backend IP address. If the problem persits consult <a href="https://trac.torproject.org/";>the bugtracker.</a></p>
+	<strong>JavaScript Error!</strong><p>There is a problem with your
+	javascript environment, you may have noscript enabled on the remote
+	onionoo backend. Try temporarily allowing noscript to connect to the
+	backend IP address. If the problem persits consult <a
+		href="https://trac.torproject.org/";>the bugtracker.</a></p>
+    </div>
+    <% } else if (error == 5) { %>
+    <div class="alert alert-error">
+        <strong>No query submitted!</strong><p>The search query was found
+	to be empty, which is not supported. You must enter a search query
+	in order to generate results. Please have a look at <a href="#/about">
+        this page</a> that explains what type of search queries are supported
+        by Atlas.</p>
     </div>
     <% } %>
 <% } else { %>
+    <% if (error == 4) { %>
+    <div class="alert alert-error">
+        <strong>Too many matches!</strong><p>The current version of
+        Atlas does not support a result set greater than 50 and only displays
+        the first 50 hits. This is due to some performance issues in doing
+        multiple parallel connections in JavaScript. Future versions will
+        hopefully manage to overcome this issue.</p>
+    </div>
+    <% } %>
+
 <table cellpadding="0" cellspacing="0" border="0" class="table table-bordered table-striped" id="torstatus_results">
 	<thead>
 		<tr>

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits