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:
+11
-6
@@ -996,13 +996,18 @@ func (r *NostrRoot) publishNote(path string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, url := range relays {
|
for _, url := range relays {
|
||||||
connectCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
nm := nostr.NormalizeURL(url)
|
||||||
relay, err := nostr.RelayConnect(connectCtx, url, r.sys.Pool.RelayOptions)
|
relay, ok := r.sys.Pool.Relays.Load(nm)
|
||||||
cancel()
|
if !ok || relay == nil || !relay.IsConnected() {
|
||||||
if err != nil {
|
connectCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||||
continue
|
var err error
|
||||||
|
relay, err = nostr.RelayConnect(connectCtx, url, r.sys.Pool.RelayOptions)
|
||||||
|
cancel()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
r.sys.Pool.Relays.Store(nm, relay)
|
||||||
}
|
}
|
||||||
r.sys.Pool.Relays.Store(nostr.NormalizeURL(url), relay)
|
|
||||||
relay.Publish(ctx, *evt)
|
relay.Publish(ctx, *evt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user