From 15dc2dff450bb2b1511870161d5970e87e83b007 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 11 Jul 2023 11:04:16 -0300 Subject: [PATCH] small context tweaks. --- nostr.go | 17 +++++++++-------- render.go | 5 ++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/nostr.go b/nostr.go index ebc47a3..8c5b7b8 100644 --- a/nostr.go +++ b/nostr.go @@ -132,18 +132,19 @@ func getLastNotes(ctx context.Context, code string) []*nostr.Event { if pp == nil { return nil } - - ctx, cancel := context.WithTimeout(ctx, time.Millisecond*1500) - defer cancel() - relays := pp.Relays - for _, relay := range sdk.FetchRelaysForPubkey(ctx, pool, pp.PublicKey, pp.Relays...) { - if relay.Outbox { - relays = append(relays, relay.URL) + + { + ctx, cancel := context.WithTimeout(ctx, time.Millisecond*1500) + defer cancel() + for _, relay := range sdk.FetchRelaysForPubkey(ctx, pool, pp.PublicKey, pp.Relays...) { + if relay.Outbox { + relays = append(relays, relay.URL) + } } } - ctx, cancel = context.WithTimeout(ctx, time.Second*4) + ctx, cancel := context.WithTimeout(ctx, time.Second*4) defer cancel() relays = append(relays, getRelay()) diff --git a/render.go b/render.go index 2bab2b8..ff3ad10 100644 --- a/render.go +++ b/render.go @@ -117,7 +117,10 @@ func render(w http.ResponseWriter, r *http.Request) { } else { typ = "other" } - author, _ = getEvent(r.Context(), npub) + + ctx, cancel := context.WithTimeout(r.Context(), time.Second*3) + author, _ = getEvent(ctx, npub) + cancel() } kindDescription := kindNames[event.Kind]