chore(stdiscosrv): properly clean out old addresses from memory

This commit is contained in:
Jakob Borg 2024-09-15 14:20:59 +02:00
parent c8ee2a5cf6
commit ce1e259bb4
No known key found for this signature in database

View File

@ -169,8 +169,16 @@ func (s *inMemoryStore) calculateStatistics() {
n++
addresses := expire(rec.Addresses, now)
if len(addresses) == 0 {
rec.Addresses = nil
s.m.Store(key, rec)
} else if len(addresses) != len(rec.Addresses) {
rec.Addresses = addresses
s.m.Store(key, rec)
}
switch {
case len(addresses) > 0:
case len(rec.Addresses) > 0:
current++
seenIPv4, seenIPv6, seenIPv6GUA := false, false, false
for _, addr := range rec.Addresses {
@ -428,6 +436,9 @@ func expire(addrs []DatabaseAddress, now time.Time) []DatabaseAddress {
naddrs = append(naddrs, addrs[i])
}
}
if len(naddrs) == 0 {
return nil
}
return naddrs
}