Skip to content
Permalink
Browse files
Allow returning up to 500 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 500 results can be rendered reasonably.
 * Limits the result set to a maximum of 500 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. (:
  • Loading branch information
irl committed Jun 11, 2016
1 parent 0de1c97 commit b2ac2eeed6afbf984124b52d79582b98b82f70d7
Showing with 57 additions and 23 deletions.
  1. +17 −10 js/collections/results.js
  2. +9 −4 js/router.js
  3. +3 −3 js/views/search/do.js
  4. +28 −6 templates/search/do.html
@@ -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 > 500) {
relays = relays.slice(0, 500);
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);
}
});
@@ -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();
}
});
@@ -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);
}
@@ -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 500 and only displays
the first 500 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>

0 comments on commit b2ac2ee

Please sign in to comment.