mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
pool: deduplicate relay urls list.
This commit is contained in:
parent
4dc6e21f60
commit
1a7b8991a3
12
pool.go
12
pool.go
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user