fix(api): SNMP/hosts — одна строка на IP (DISTINCT ON), лимиты для больших сканов

Made-with: Cursor
This commit is contained in:
Луценко Андрей Анатольевич
2026-04-10 15:35:45 +10:00
parent 009aeb5dbf
commit a36edbc26b
4 changed files with 69 additions and 36 deletions
+15 -6
View File
@@ -291,12 +291,17 @@ values ($1, $2, $3, $4)`
func (s *PostgresStore) ListHostResults(scanID string, limit int) []HostResult {
if limit <= 0 {
limit = 500
limit = 200000
}
// Одна актуальная строка на IP (иначе при limit по времени часть хостов без SNMP в UI).
query := `
select ip::text, is_up, checked_at
from scan_hosts
where scan_id = $1
from (
select distinct on (ip) ip, is_up, checked_at
from scan_hosts
where scan_id = $1
order by ip asc, checked_at desc
) t
order by checked_at desc
limit $2`
rows, err := s.db.QueryContext(context.Background(), query, scanID, limit)
@@ -380,13 +385,17 @@ values ($1, $2, $3, $4, $5, $6, $7, $8)`
func (s *PostgresStore) ListSNMPResults(scanID string, limit int) []SNMPResult {
if limit <= 0 {
limit = 1000
limit = 200000
}
query := `
select ip::text, success, coalesce(sys_name, ''), coalesce(sys_descr, ''), coalesce(sys_object_id, ''),
coalesce(error_text, ''), checked_at
from scan_snmp
where scan_id = $1
from (
select distinct on (ip) ip, success, sys_name, sys_descr, sys_object_id, error_text, checked_at
from scan_snmp
where scan_id = $1
order by ip asc, checked_at desc
) t
order by checked_at desc
limit $2`
rows, err := s.db.QueryContext(context.Background(), query, scanID, limit)