fix(dashboard): add COALESCE to SQL aggregations and empty-state handling for charts
Some checks failed
CI / Check (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Formatting (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Release Build (push) Has been cancelled

Backend: wrap SUM() queries with COALESCE in handle_time_series,
handle_clients_usage, and handle_detailed_usage to prevent NULL-induced
panics when no data exists for a time window.

Frontend: add showEmptyChart() empty-state messages and error feedback
across overview, analytics, costs, and clients pages. Rewrite analytics
loadCharts() to use Promise.allSettled() so each chart renders
independently on partial API failures.
This commit is contained in:
2026-03-02 11:48:17 -05:00
parent 9c01b97f82
commit e4cf088071
5 changed files with 134 additions and 17 deletions

View File

@@ -104,8 +104,8 @@ pub(super) async fn handle_time_series(State(state): State<DashboardState>) -> J
SELECT
strftime('%H:00', timestamp) as hour,
COUNT(*) as requests,
SUM(total_tokens) as tokens,
SUM(cost) as cost
COALESCE(SUM(total_tokens), 0) as tokens,
COALESCE(SUM(cost), 0.0) as cost
FROM llm_requests
WHERE timestamp >= ?
GROUP BY hour
@@ -155,8 +155,8 @@ pub(super) async fn handle_clients_usage(State(state): State<DashboardState>) ->
SELECT
client_id,
COUNT(*) as requests,
SUM(total_tokens) as tokens,
SUM(cost) as cost,
COALESCE(SUM(total_tokens), 0) as tokens,
COALESCE(SUM(cost), 0.0) as cost,
MAX(timestamp) as last_request
FROM llm_requests
GROUP BY client_id
@@ -255,8 +255,8 @@ pub(super) async fn handle_detailed_usage(State(state): State<DashboardState>) -
provider,
model,
COUNT(*) as requests,
SUM(total_tokens) as tokens,
SUM(cost) as cost
COALESCE(SUM(total_tokens), 0) as tokens,
COALESCE(SUM(cost), 0.0) as cost
FROM llm_requests
GROUP BY date, client_id, provider, model
ORDER BY date DESC