mirror of
https://github.com/fiatjaf/nak.git
synced 2026-10-05 15:18:23 +00:00
nostrfs: reuse pooled relay connections when publishing notes instead of leaking a new connection on every publish.
This commit is contained in:
+7
-2
@@ -996,13 +996,18 @@ func (r *NostrRoot) publishNote(path string) {
|
||||
}
|
||||
|
||||
for _, url := range relays {
|
||||
nm := nostr.NormalizeURL(url)
|
||||
relay, ok := r.sys.Pool.Relays.Load(nm)
|
||||
if !ok || relay == nil || !relay.IsConnected() {
|
||||
connectCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
relay, err := nostr.RelayConnect(connectCtx, url, r.sys.Pool.RelayOptions)
|
||||
var err error
|
||||
relay, err = nostr.RelayConnect(connectCtx, url, r.sys.Pool.RelayOptions)
|
||||
cancel()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
r.sys.Pool.Relays.Store(nostr.NormalizeURL(url), relay)
|
||||
r.sys.Pool.Relays.Store(nm, relay)
|
||||
}
|
||||
relay.Publish(ctx, *evt)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user