From 8d9bc1c422c528bc94e742de28f522dc39782d83 Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sat, 27 Jun 2026 22:18:02 +1000 Subject: [PATCH] feat: add bandwidth saved stat to dashboard (#65) Shows total bytes served from cache (instead of upstream) over the last 30 days. Queries `SUM(size_bytes) WHERE cache_hit = TRUE` from access_log. Reviewed-on: https://git.unkin.net/unkin/artifactapi/pulls/65 Co-authored-by: Ben Vincent Co-committed-by: Ben Vincent --- internal/database/stats.go | 9 +++++++++ ui/src/pages/Dashboard.tsx | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/internal/database/stats.go b/internal/database/stats.go index d21cb68..75af387 100644 --- a/internal/database/stats.go +++ b/internal/database/stats.go @@ -30,6 +30,15 @@ func (db *DB) GetOverviewStats(ctx context.Context) (*models.OverviewStats, erro return nil, err } + err = db.Pool.QueryRow(ctx, ` + SELECT COALESCE(SUM(size_bytes), 0) + FROM access_log + WHERE cache_hit = TRUE AND created_at > NOW() - INTERVAL '30 days' + `).Scan(&stats.BandwidthSaved30d) + if err != nil { + return nil, err + } + return &stats, nil } diff --git a/ui/src/pages/Dashboard.tsx b/ui/src/pages/Dashboard.tsx index 1565157..b0a5792 100644 --- a/ui/src/pages/Dashboard.tsx +++ b/ui/src/pages/Dashboard.tsx @@ -50,6 +50,11 @@ export function Dashboard() { value={formatNumber(stats.total_blobs_deduped)} sub="shared blobs" /> + {health && (