From e6018c6fd9b5a1ef387d7560ef9a2a124203cee8 Mon Sep 17 00:00:00 2001 From: Graham McInitre Date: Thu, 16 Jul 2026 08:36:00 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20pskreporter=20=E2=80=94=20eliminate=20@s?= =?UTF-8?q?pots=20crash,=20duplicate=20stream=20IDs,=20and=20slow=20aggreg?= =?UTF-8?q?ate=20blocking=20with=20start=5Fasync?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/microwaveprop_web/live/pskr_spots_live.ex | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/microwaveprop_web/live/pskr_spots_live.ex b/lib/microwaveprop_web/live/pskr_spots_live.ex index 5845db61..40d546ee 100644 --- a/lib/microwaveprop_web/live/pskr_spots_live.ex +++ b/lib/microwaveprop_web/live/pskr_spots_live.ex @@ -16,18 +16,35 @@ defmodule MicrowavepropWeb.PskrSpotsLive do _ = if connected?(socket), do: schedule_refresh() spots = fetch_recent_spots() + socket = start_async(socket, :total_spots, fn -> fetch_total_spots() end) + socket = start_async(socket, :band_counts, fn -> fetch_band_counts() end) {:ok, socket |> assign( page_title: "PSK Reporter Spots", limit: @limit, - total_spots: fetch_total_spots(), - band_counts: fetch_band_counts() + total_spots: nil, + band_counts: [], + spots_empty: spots == [] ) |> stream(:spots, spots, reset: true)} end + @impl true + def handle_async(:total_spots, {:ok, total}, socket) do + {:noreply, assign(socket, total_spots: total)} + end + + def handle_async(:band_counts, {:ok, counts}, socket) do + {:noreply, assign(socket, band_counts: counts)} + end + + def handle_async(slot, {:exit, reason}, socket) do + Logger.warning("PskrSpotsLive async #{slot} failed: #{inspect(reason)}") + {:noreply, socket} + end + @impl true def handle_info(:refresh_spots, socket) do _ = schedule_refresh() @@ -37,7 +54,8 @@ defmodule MicrowavepropWeb.PskrSpotsLive do socket |> assign( total_spots: fetch_total_spots(), - band_counts: fetch_band_counts() + band_counts: fetch_band_counts(), + spots_empty: spots == [] ) |> stream(:spots, spots, reset: true)} end @@ -112,13 +130,6 @@ defmodule MicrowavepropWeb.PskrSpotsLive do - - No spots yet - {fmt_dt(spot.last_spot_at)} {spot.band} @@ -141,7 +152,7 @@ defmodule MicrowavepropWeb.PskrSpotsLive do -

+

No PSK Reporter spots received yet. The MQTT listener is running — spots will appear here as they arrive.