diff --git a/lib/microwaveprop_web/live/status_live.ex b/lib/microwaveprop_web/live/status_live.ex index 3fa6eb96..92402f75 100644 --- a/lib/microwaveprop_web/live/status_live.ex +++ b/lib/microwaveprop_web/live/status_live.ex @@ -85,11 +85,12 @@ defmodule MicrowavepropWeb.StatusLive do end defp count_unprocessed_raw do - # Previously issued 7 separate `SELECT COUNT(*) FROM contacts WHERE - # IN (...)` queries. Postgres ran 7 index scans over the - # same 58k+ row table on every 2s status refresh; collapse into a - # single scan that returns every needed count via FILTER clauses. - %{rows: [[total, terrain, hrrr, weather, iemre, radar, all_done]]} = + # One scan over the contacts table returns every per-type pending + # count via FILTER clauses. Cheaper than N separate COUNT queries + # and cheaper than N index scans. Keep the FILTER list in lockstep + # with the progress-bar list in the template — missing a field + # here means the progress bar will deny-count its own column. + %{rows: [[total, terrain, hrrr, weather, iemre, radar, mechanism, all_done]]} = Repo.query!(""" SELECT COUNT(*) FILTER (WHERE pos1 IS NOT NULL), @@ -103,6 +104,8 @@ defmodule MicrowavepropWeb.StatusLive do AND iemre_status::text IN ('pending','queued','processing','failed')), COUNT(*) FILTER (WHERE pos1 IS NOT NULL AND radar_status::text IN ('pending','queued','processing','failed')), + COUNT(*) FILTER (WHERE pos1 IS NOT NULL + AND mechanism_status::text IN ('pending','queued','processing','failed')), COUNT(*) FILTER (WHERE pos1 IS NOT NULL AND hrrr_status::text IN ('complete','unavailable') AND weather_status::text IN ('complete','unavailable') @@ -120,6 +123,7 @@ defmodule MicrowavepropWeb.StatusLive do weather: weather, iemre: iemre, radar: radar, + mechanism: mechanism, narr_candidates: narr_candidates, narr_done: narr_done, remaining: max(terrain, max(hrrr, max(weather, iemre))), @@ -461,6 +465,7 @@ defmodule MicrowavepropWeb.StatusLive do {"terrain", "Terrain", @unprocessed.total - @unprocessed.terrain, @unprocessed.total}, {"iemre", "IEMRE", @unprocessed.total - @unprocessed.iemre, @unprocessed.total}, {"radar", "Radar", @unprocessed.total - @unprocessed.radar, @unprocessed.total}, + {"mechanism", "Mechanism", @unprocessed.total - @unprocessed.mechanism, @unprocessed.total}, {"narr", "NARR", @unprocessed.narr_done, @unprocessed.narr_candidates} ] do %> <% pct = if denom > 0, do: round(complete * 100 / denom), else: 0 %>