Fix AS detail view and add prefix sorting

- Fix GetASDetails to properly handle timestamp from MAX(last_updated)
- Parse timestamp string from SQLite aggregate function result
- Add natural sorting of prefixes by IP address in AS detail view
- Sort IPv4 and IPv6 prefixes separately by network address
- Remove SQL ORDER BY since we're sorting in Go
- This fixes the issue where AS detail pages showed no prefixes
This commit is contained in:
2025-07-28 04:42:10 +02:00
parent 48db8b9edf
commit 9b649c98c9
2 changed files with 54 additions and 2 deletions

View File

@@ -773,7 +773,6 @@ func (d *Database) GetASDetails(asn int) (*ASN, []LiveRoute, error) {
FROM live_routes
WHERE origin_asn = ?
GROUP BY prefix, mask_length, ip_version
ORDER BY ip_version, mask_length, prefix
`
rows, err := d.db.Query(query, asn)
@@ -785,10 +784,24 @@ func (d *Database) GetASDetails(asn int) (*ASN, []LiveRoute, error) {
var prefixes []LiveRoute
for rows.Next() {
var route LiveRoute
err := rows.Scan(&route.Prefix, &route.MaskLength, &route.IPVersion, &route.LastUpdated)
var lastUpdatedStr string
err := rows.Scan(&route.Prefix, &route.MaskLength, &route.IPVersion, &lastUpdatedStr)
if err != nil {
d.logger.Error("Failed to scan prefix row", "error", err, "asn", asn)
continue
}
// Parse the timestamp string
route.LastUpdated, err = time.Parse("2006-01-02 15:04:05-07:00", lastUpdatedStr)
if err != nil {
// Try without timezone
route.LastUpdated, err = time.Parse("2006-01-02 15:04:05", lastUpdatedStr)
if err != nil {
d.logger.Error("Failed to parse timestamp", "error", err, "timestamp", lastUpdatedStr)
continue
}
}
route.OriginASN = asn
prefixes = append(prefixes, route)
}