Commit e520e515 authored by Iain R. Learmonth's avatar Iain R. Learmonth Committed by Philipp Winter
Browse files

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. (:
parent 0de1c972
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -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;
                            }
                            lookedUp();
                        },
                        error: function() {
                            console.log("error in loading..");
                            console.log("error in loading one relay..");
                            lookedUp();
                            error(0);
                        }
                    });
+9 −4
Original line number Diff line number Diff line
@@ -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();
                }
            });
+3 −3
Original line number Diff line number Diff line
@@ -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);
	    }
+28 −6
Original line number Diff line number Diff line
@@ -24,10 +24,32 @@
    </div>
    <% } 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>