mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-09 15:49:56 +02:00
use @mmalmi json string preparsing speedup for duplicate events
- get rid of "nonUnique" variants of subMany as we can now relay on CheckDuplicate to track relays. - add global pool tracker duplicateMiddleware.
This commit is contained in:
18
relay.go
18
relay.go
@ -220,6 +220,17 @@ func (r *Relay) ConnectWithTLS(ctx context.Context, tlsConfig *tls.Config) error
|
||||
|
||||
message := buf.Bytes()
|
||||
debugLogf("{%s} received %v\n", r.URL, message)
|
||||
|
||||
// if this is an "EVENT" we will have this preparser logic that should speed things up a little
|
||||
// as we skip handling duplicate events
|
||||
subid := extractSubID(message)
|
||||
subscription, ok := r.Subscriptions.Load(subIdToSerial(subid))
|
||||
if ok && subscription.CheckDuplicate != nil {
|
||||
if !subscription.CheckDuplicate(extractEventID(message[10+len(subid):]), r.URL) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
envelope := ParseMessage(message)
|
||||
if envelope == nil {
|
||||
if r.customHandler != nil {
|
||||
@ -242,11 +253,8 @@ func (r *Relay) ConnectWithTLS(ctx context.Context, tlsConfig *tls.Config) error
|
||||
}
|
||||
r.challenge = *env.Challenge
|
||||
case *EventEnvelope:
|
||||
if env.SubscriptionID == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if subscription, ok := r.Subscriptions.Load(subIdToSerial(*env.SubscriptionID)); !ok {
|
||||
// we already have the subscription from the pre-check above, so we can just reuse it
|
||||
if subscription == nil {
|
||||
// InfoLogger.Printf("{%s} no subscription with id '%s'\n", r.URL, *env.SubscriptionID)
|
||||
continue
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user