mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
fix FetchSpecificEvent() behavior for the faster no-relays case.
This commit is contained in:
parent
9e744e1eb0
commit
7ede46661c
@ -74,30 +74,36 @@ func (sys *System) FetchSpecificEvent(
|
||||
}
|
||||
|
||||
var result *nostr.Event
|
||||
fetchProfileOnce := sync.Once{}
|
||||
|
||||
attempts:
|
||||
for _, attempt := range []struct {
|
||||
label string
|
||||
relays []string
|
||||
nonUnique bool
|
||||
label string
|
||||
relays []string
|
||||
slowWithRelays bool
|
||||
}{
|
||||
{
|
||||
label: "fetch-" + prefix,
|
||||
relays: relays,
|
||||
// set this to true if the caller wants relays, so we won't return immediately
|
||||
// but will instead wait a little while to see if more relays respond
|
||||
nonUnique: withRelays,
|
||||
slowWithRelays: withRelays,
|
||||
},
|
||||
{
|
||||
label: "fetchf-" + prefix,
|
||||
relays: fallback,
|
||||
nonUnique: false,
|
||||
label: "fetchf-" + prefix,
|
||||
relays: fallback,
|
||||
slowWithRelays: false,
|
||||
},
|
||||
} {
|
||||
// actually fetch the event here
|
||||
countdown := 6.0
|
||||
subManyCtx := ctx
|
||||
subMany := sys.Pool.SubManyEose
|
||||
if attempt.slowWithRelays {
|
||||
subMany = sys.Pool.SubManyEoseNonUnique
|
||||
}
|
||||
|
||||
if attempt.nonUnique {
|
||||
if attempt.slowWithRelays {
|
||||
// keep track of where we have actually found the event so we can show that
|
||||
var cancel context.CancelFunc
|
||||
subManyCtx, cancel = context.WithTimeout(ctx, time.Second*6)
|
||||
@ -115,9 +121,7 @@ func (sys *System) FetchSpecificEvent(
|
||||
}()
|
||||
}
|
||||
|
||||
fetchProfileOnce := sync.Once{}
|
||||
|
||||
for ie := range sys.Pool.SubManyEoseNonUnique(
|
||||
for ie := range subMany(
|
||||
subManyCtx,
|
||||
attempt.relays,
|
||||
nostr.Filters{filter},
|
||||
@ -131,6 +135,11 @@ func (sys *System) FetchSpecificEvent(
|
||||
if result == nil || ie.CreatedAt > result.CreatedAt {
|
||||
result = ie.Event
|
||||
}
|
||||
|
||||
if !attempt.slowWithRelays {
|
||||
break attempts
|
||||
}
|
||||
|
||||
countdown = min(countdown-0.5, 1)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user