From a574a75610466b09a657f4a4689f76b21c91251f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 5 Jan 2018 16:10:24 +0100 Subject: [PATCH] Advanced search JS: avoid re-querying for the same thing --- src/scripts/tutti/4_search.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/scripts/tutti/4_search.js b/src/scripts/tutti/4_search.js index 1a42b846..9f62f692 100644 --- a/src/scripts/tutti/4_search.js +++ b/src/scripts/tutti/4_search.js @@ -12,6 +12,7 @@ var elasticSearcher = (function() { newhits: [], terms: {}, page: 0, + last_params: null, // to prevent re-querying for the same thing. setQuery: (function(q, _url){ deze.query=q; @@ -66,6 +67,12 @@ var elasticSearcher = (function() { q: deze.query, page: deze.page, }; + + if (deze.last_params != null && deze.last_params.q == params.q && deze.last_params.page == params.page) { + // We're requesting exactly the same thing as before, don't bother. + return; + } + //add term filters Object.assign(params, deze.terms); @@ -80,6 +87,7 @@ var elasticSearcher = (function() { deze.newhits = newhits.slice(0); //cb(newhits.slice(0)); + deze.last_params = params; deze.results({ 'count': data.hits.total, 'hits': newhits.slice(0), @@ -90,6 +98,7 @@ var elasticSearcher = (function() { }) .fail(function(err) { toastr.error(xhrErrorResponseMessage(err), 'Unable to perform search:'); + deze.last_params = null; }) ;