fix: news seen map eviction strategy — keep half instead of clearing all

Previously when the seen map exceeded 1000 entries, ALL entries were
deleted, losing dedup state and causing re-notifications. Now evicts
~half the entries, preserving recent URLs for dedup continuity.
This commit is contained in:
shinchan-zhai
2026-03-23 09:54:31 +08:00
parent 6acf925a0b
commit 9a81fa5e84

View File

@@ -105,7 +105,15 @@ func (b *Brain) scanNews(seen map[string]bool) {
emoji, d.Title, d.Source, sentiment))
}
if len(seen) > 1000 { for k := range seen { delete(seen, k) } }
// Evict ~half when seen map gets large (keep recent half to avoid re-notifying)
if len(seen) > 1000 {
i, half := 0, len(seen)/2
for k := range seen {
if i >= half { break }
delete(seen, k)
i++
}
}
}
func (b *Brain) StartMarketBriefs(hours []int) {