pool: deduplicate relay urls list.

This commit is contained in:
fiatjaf 2024-01-18 11:49:16 -03:00
parent 4dc6e21f60
commit 1a7b8991a3
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

12
pool.go
View File

@ -9,6 +9,7 @@ import (
"time"
"github.com/puzpuzpuz/xsync/v3"
"golang.org/x/exp/slices"
)
const (
@ -107,7 +108,14 @@ func (pool *SimplePool) subMany(ctx context.Context, urls []string, filters Filt
pending := xsync.NewCounter()
pending.Add(int64(len(urls)))
for _, url := range urls {
for i, url := range urls {
url = NormalizeURL(url)
urls[i] = url
if idx := slices.Index(urls, url); idx != i {
// skip duplicate relays in the list
continue
}
go func(nm string) {
defer func() {
pending.Dec()
@ -202,7 +210,7 @@ func (pool *SimplePool) subMany(ctx context.Context, urls []string, filters Filt
time.Sleep(interval)
interval = interval * 17 / 10 // the next time we try we will wait longer
}
}(NormalizeURL(url))
}(url)
}
return events