Extract dashboard assembly from main.py; stop the 13-request live SPC fan-out per page load #58
Labels
No labels
area:ai
area:ci-cd
area:notifications
area:observability
area:public-pages
backlog
bug
duplicate
enhancement
help wanted
invalid
question
type:decision
type:feature
type:infra
type:maintenance
type:security
v1.0.1
v1.1.0
v1.2.0
v1.3.0
v2.0.0
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rbrooks/WeatherBot#58
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The dashboard route (app/main.py:138-444) contains ~300 lines of SPC
grouping/risk logic plus a "live fallback" that awaits 13 SPC fetches
(main.py:283-317) on every page load with no caching anywhere in
spc.py/nws.py for those calls — while the scheduler polls the same data every
5 minutes. Extract assembly into a service; serve live-fallback data from a
short-TTL cache shared with the poller (or drop the fallback in favor of
dashboard records). Consolidate the duplicated match-context builders
(spc_processor.py:232-273 vs spc_impacts.py:70-107 — already drifted:
guidancekey,_metadata_valuesanitization). Delete the dead_on_notifyhandler (app/api/sse.py:42-43) while touching adjacent code.
Acceptance criteria:
Filed from the 2026-07-17 codebase audit (
docs/.internal/report-2026-07-17.md), finding F-19.Done in #110 (merged). Both parts:
Dashboard extraction + no live fan-out. New
app/services/dashboard.pybuild_dashboard_context(request, user)owns the assembly; the/route is now auth + service call + render (~10 lines, down from ~318). The 13-request live SPC fan-out is removed —poll_spc_dashboardalready upserts dashboard SPC records for all enabled+ready locations every cycle, so the dashboard reads outlooks purely from DB records and makes zero direct SPC upstream requests on load (asserted by a test that fails if any fetcher is called)._is_livewas unused by any template; the dead_on_notifythe audit cited was already removed by the #53 SSE broker rewrite (only the live_on_notificationremains).Match-context consolidation. The two drifted builders are now one
spc_outlook_match_contextinspc_impacts.py— the correct superset (_metadata_valuesanitization +guidance+is_extended/spc_product_family); the notification-path builder was deleted and its caller routed through the shared one. Intended drift fixes: the impact path now also gets guidance + sanitized values, and the notificationlocation_match.product_familyis the canonicalspc_convective_outlook(a context string the summary validators don't key on;payload.product_familyunchanged).All acceptance criteria met. ruff clean; bulk 670 passed; postgres tier 4 passed on the dev server.
Minor follow-up (not in scope here): the separate
/spc/outlooksAPI endpoint still fetches SPC live per request — a candidate for the same records-based treatment if it ever matters.