From e0d9ffcbc12f0bdf42cbb036646a23ee43fbf6e0 Mon Sep 17 00:00:00 2001 From: wn_ Date: Sat, 15 Feb 2025 16:44:02 +0000 Subject: Only continue filter testing when there are likely more entries to check. Prior to this, a filter test could needlessly result in up to 100 backend requests (limit 100, max_offset 10000) when the filter's associated feeds+categories have fewer than 10000 entries. --- js/CommonFilters.js | 60 +++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'js') diff --git a/js/CommonFilters.js b/js/CommonFilters.js index fb1cfacb9..7b7d64958 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -30,52 +30,48 @@ const Filters = { params.offset = offset; params.limit = test_dialog.limit; - console.log("getTestResults:" + offset); - xhr.json("backend.php", params, (result) => { try { if (result && test_dialog && test_dialog.open) { - test_dialog.results += result.length; - - console.log("got results:" + result.length); - const loading_message = test_dialog.domNode.querySelector(".loading-message"); const results_list = test_dialog.domNode.querySelector(".filter-results-list"); - loading_message.innerHTML = __("Looking for articles (%d processed, %f found)...") - .replace("%f", test_dialog.results) - .replace("%d", offset); + if (result.pre_filtering_count > 0) { + test_dialog.results += result.items.length; - console.log(offset + " " + test_dialog.max_offset); + loading_message.innerHTML = __("Looking for articles (%d processed, %f found)...") + .replace("%f", test_dialog.results) + .replace("%d", offset); - for (let i = 0; i < result.length; i++) { - const tmp = dojo.create("div", { innerHTML: result[i]}); + for (let i = 0; i < result.items.length; i++) { + const tmp = dojo.create("div", { innerHTML: result.items[i]}); - results_list.innerHTML += tmp.innerHTML; - } - - if (test_dialog.results < 30 && offset < test_dialog.max_offset) { + results_list.innerHTML += tmp.innerHTML; + } - // get the next batch - window.setTimeout(function () { - test_dialog.getTestResults(params, offset + test_dialog.limit); - }, 0); + // get the next batch if there may be more available and testing limits haven't been reached + if (result.pre_filtering_count === test_dialog.limit && + test_dialog.results < 30 && + offset < test_dialog.max_offset) { + window.setTimeout(function () { + test_dialog.getTestResults(params, offset + test_dialog.limit); + }, 0); - } else { - // all done - - test_dialog.domNode.querySelector(".loading-indicator").hide(); + return; + } + } - if (test_dialog.results == 0) { - results_list.innerHTML = `
  • - ${__('No recent articles matching this filter have been found.')}
  • `; + // all done-- either the backend found no more pre-filtering entries, or test limits were reached + test_dialog.domNode.querySelector(".loading-indicator").hide(); - loading_message.innerHTML = __("Articles matching this filter:"); - } else { - loading_message.innerHTML = __("Found at least %d articles matching this filter:") - .replace("%d", test_dialog.results); - } + if (test_dialog.results == 0) { + results_list.innerHTML = `
  • + ${__('No recent articles matching this filter have been found.')}
  • `; + loading_message.innerHTML = __("Articles matching this filter:"); + } else { + loading_message.innerHTML = __("Found at least %d articles matching this filter:") + .replace("%d", test_dialog.results); } } else if (!result) { -- cgit v1.2.3-54-g00ecf