Fix prefix stats by counting from live routes tables

The prefixes_v4 and prefixes_v6 tables were never being populated
because GetOrCreatePrefix was not being called anywhere. Since we
already track all prefixes in live_routes_v4 and live_routes_v6,
update stats queries to count distinct prefixes from those tables.
This commit is contained in:
Jeffrey Paul 2025-07-28 22:44:44 +02:00
parent 725d04ffa8
commit a165ecf759
2 changed files with 113291 additions and 748 deletions

View File

@ -815,13 +815,13 @@ func (d *Database) GetStatsContext(ctx context.Context) (Stats, error) {
return stats, err return stats, err
} }
// Count prefixes from both tables // Count unique prefixes from live routes tables
err = d.db.QueryRowContext(ctx, "SELECT COUNT(*) FROM prefixes_v4").Scan(&stats.IPv4Prefixes) err = d.db.QueryRowContext(ctx, "SELECT COUNT(DISTINCT prefix) FROM live_routes_v4").Scan(&stats.IPv4Prefixes)
if err != nil { if err != nil {
return stats, err return stats, err
} }
err = d.db.QueryRowContext(ctx, "SELECT COUNT(*) FROM prefixes_v6").Scan(&stats.IPv6Prefixes) err = d.db.QueryRowContext(ctx, "SELECT COUNT(DISTINCT prefix) FROM live_routes_v6").Scan(&stats.IPv6Prefixes)
if err != nil { if err != nil {
return stats, err return stats, err
} }

114033
log.txt

File diff suppressed because it is too large Load Diff