+21
-11
internal/storage/postgres.go
+21
-11
internal/storage/postgres.go
···
864
864
err := p.db.QueryRowContext(ctx, query).Scan(
865
865
&stats.TotalEndpoints, &stats.OnlineEndpoints, &stats.OfflineEndpoints,
866
866
)
867
+
if err != nil {
868
+
return nil, err
869
+
}
867
870
868
871
// Get average response time from recent scans
869
872
avgQuery := `
···
872
875
WHERE response_time > 0 AND scanned_at > NOW() - INTERVAL '1 hour'
873
876
`
874
877
var avgResponseTime sql.NullFloat64
875
-
p.db.QueryRowContext(ctx, avgQuery).Scan(&avgResponseTime)
878
+
_ = p.db.QueryRowContext(ctx, avgQuery).Scan(&avgResponseTime)
876
879
if avgResponseTime.Valid {
877
880
stats.AvgResponseTime = avgResponseTime.Float64
878
881
}
···
898
901
899
902
// Get total DIDs from latest PDS scans
900
903
didQuery := `
901
-
WITH latest_pds_scans AS (
902
-
SELECT DISTINCT ON (endpoint_id)
903
-
endpoint_id,
904
-
user_count
905
-
FROM endpoint_scans
906
-
WHERE endpoint_id IN (SELECT id FROM endpoints WHERE endpoint_type = 'pds')
907
-
ORDER BY endpoint_id, scanned_at DESC
904
+
WITH unique_servers AS (
905
+
SELECT DISTINCT ON (COALESCE(e.server_did, e.id::text))
906
+
e.id
907
+
FROM endpoints e
908
+
WHERE e.endpoint_type = 'pds'
909
+
ORDER BY COALESCE(e.server_did, e.id::text), e.discovered_at ASC
910
+
),
911
+
latest_pds_scans AS (
912
+
SELECT DISTINCT ON (us.id)
913
+
us.id,
914
+
es.user_count
915
+
FROM unique_servers us
916
+
LEFT JOIN endpoint_scans es ON us.id = es.endpoint_id
917
+
ORDER BY us.id, es.scanned_at DESC
908
918
)
909
919
SELECT SUM(user_count) FROM latest_pds_scans
910
920
`
911
921
var totalDIDs sql.NullInt64
912
-
p.db.QueryRowContext(ctx, didQuery).Scan(&totalDIDs)
922
+
_ = p.db.QueryRowContext(ctx, didQuery).Scan(&totalDIDs)
913
923
if totalDIDs.Valid {
914
924
stats.TotalDIDs = totalDIDs.Int64
915
925
}
···
1695
1705
pbc.country,
1696
1706
pbc.country_code,
1697
1707
pbc.active_pds_count,
1698
-
ROUND((pbc.active_pds_count * 100.0 / NULLIF(t.total_pds, 0))::numeric, 4) as pds_percentage,
1708
+
ROUND((pbc.active_pds_count * 100.0 / NULLIF(t.total_pds, 0))::numeric, 2) as pds_percentage,
1699
1709
COALESCE(pbc.total_users, 0) as total_users,
1700
-
ROUND((COALESCE(pbc.total_users, 0) * 100.0 / NULLIF(t.total_users_global, 0))::numeric, 4) as users_percentage,
1710
+
ROUND((COALESCE(pbc.total_users, 0) * 100.0 / NULLIF(t.total_users_global, 0))::numeric, 2) as users_percentage,
1701
1711
ROUND(COALESCE(pbc.avg_response_time, 0)::numeric, 2) as avg_response_time_ms
1702
1712
FROM pds_by_country pbc
1703
1713
CROSS JOIN totals t