Skip to content

Commit

Permalink
in the last commits we had forgotten to handle the case in which ther…
Browse files Browse the repository at this point in the history
…e was no WithLabel().
  • Loading branch information
fiatjaf committed Sep 29, 2024
1 parent 05eb11e commit fe35088
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,18 +409,23 @@ func (r *Relay) PrepareSubscription(ctx context.Context, filters Filters, opts .
match: filters.Match,
}

label := ""
for _, opt := range opts {
switch o := opt.(type) {
case WithLabel:
buf := subIdPool.Get().([]byte)[:0]
buf = strconv.AppendInt(buf, sub.counter, 10)
buf = append(buf, ':')
buf = append(buf, string(o)...)
defer subIdPool.Put(buf)
sub.id = string(buf)
label = string(o)
}
}

// subscription id calculation
buf := subIdPool.Get().([]byte)[:0]
buf = strconv.AppendInt(buf, sub.counter, 10)
buf = append(buf, ':')
buf = append(buf, label...)
defer subIdPool.Put(buf)
sub.id = string(buf)

// we track subscriptions only by their counter, no need for the full id
r.Subscriptions.Store(int64(sub.counter), sub)

// start handling events, eose, unsub etc:
Expand Down

0 comments on commit fe35088

Please sign in to comment.