From 5ac1697e0832635eed1f2929ba2dc45f0a2be2e9 Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Fri, 3 Oct 2025 14:07:59 +0100 Subject: [PATCH] Don't supply query parameters to the API unless they are required --- webassets/js/code.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/webassets/js/code.js b/webassets/js/code.js index ee9e426..09b4036 100644 --- a/webassets/js/code.js +++ b/webassets/js/code.js @@ -24,8 +24,12 @@ function loadSpots() { // Build a query string for the API, based on the filters that the user has selected. function buildQueryString() { var str = "?"; - var filterNames = ["dx_continent", "de_continent", "mode_type", "source", "band"]; - str = str + filterNames.map(n => { return getQueryStringFor(n); }).join("&"); + ["dx_continent", "de_continent", "mode_type", "source", "band"].forEach(fn => { + if (!allFilterOptionsSelected(fn)) { + str = str + getQueryStringFor(fn) + "&"; + } + }); + str = str + "limit=50"; return str; } @@ -43,6 +47,15 @@ function getSelectedFilterOptions(parameter) { }).get().join(","); } +// For a parameter, such as dx_continent, return true if all possible options are enabled. (In this case, we don't need +// to bother sending this as one of the query parameters to the API; no parameter provided implies "send everything".) +function allFilterOptionsSelected(parameter) { + var filter = $(".filter-button-" + parameter).filter(function() { + return !this.checked; + }).get(); + return filter.length == 0; +} + // Update the spots table function updateTable() { // Populate table with headers