Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion radio-fetch
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,37 @@ store_random_results() {
}

refresh_world_cache() {
local world_tmp nepal_tmp merged_tmp
world_tmp=$(mktemp "$runtime_dir/world-XXXXXX")
nepal_tmp=$(mktemp "$runtime_dir/nepal-XXXXXX")
merged_tmp=$(mktemp "$runtime_dir/merged-XXXXXX")

request 500 '/json/stations/search' \
--data-urlencode 'has_geo_info=true' \
--data-urlencode 'hidebroken=true' \
--data-urlencode 'order=clickcount' \
--data-urlencode 'reverse=true' \
--data-urlencode 'limit=500' \
| store_results "$world_cache_file" >/dev/null
> "$world_tmp" 2>/dev/null || { rm -f "$world_tmp" "$nepal_tmp" "$merged_tmp"; return 1; }

curl -s --max-time 12 \
"https://all.api.radio-browser.info/json/stations/bycountrycodeexact/NP?hidebroken=true&order=clickcount&reverse=true&limit=100" \
> "$nepal_tmp" 2>/dev/null || true
Comment on lines +207 to +209

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Reuse the bounded request helper

This direct curl call skips the existing 4 MiB response limit, record-count validation, retries, and server fallback. limit=100 is a server query parameter, not a client-side bound; I confirmed an oversized Nepal response is accepted. Route the request through request 100 with the existing query-argument convention, and preserve the world-only fallback when the optional request fails.


if [[ -s "$nepal_tmp" ]] && jq -e 'type == "array" and length > 0' "$nepal_tmp" >/dev/null 2>&1; then
jq -s '
(.[0] // []) as $world
| (.[1] // []) as $nepal
| ($world | map(.stationuuid // "")) as $world_uuids
| ($nepal | map(select(.stationuuid as $u | ($world_uuids | index($u)) == null))) as $new
| ($new + $world)[:500]
' "$world_tmp" "$nepal_tmp" > "$merged_tmp"
Comment on lines +215 to +218

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve all priority stations before truncating

Nepal stations already in $world are removed from $new, so they retain their original positions and can be cut off by [:500]. I reproduced a 500-station world list with three Nepal stations at the tail and a 31-station Nepal response: the result contains only 28 Nepal stations. If country prioritization is retained, put the complete priority list first, deduplicate by UUID while preserving order, then apply the cap. Add a regression case with overlapping stations near the cutoff.

store_results "$world_cache_file" < "$merged_tmp" >/dev/null

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Publish the initial world data before fetching enrichment

With no valid cache, fetch_world waits for this function before returning any stations. The Nepal request runs after the world request and can add its full 12-second timeout even when the world response succeeded. A fixture with a one-second Nepal timeout added that second to first load. Return the available world data first and load any extra country coverage through the existing background expansion flow.

else
store_results "$world_cache_file" < "$world_tmp" >/dev/null
fi

rm -f "$world_tmp" "$nepal_tmp" "$merged_tmp"
}

refresh_world_cache_in_background() {
Expand Down