allocate subscription id only once on creation.

This commit is contained in:
fiatjaf
2024-09-29 16:29:10 -03:00
parent 24343dbbef
commit ad14daec9f
2 changed files with 13 additions and 20 deletions

View File

@ -7,6 +7,7 @@ import (
"fmt"
"log"
"net/http"
"strconv"
"sync"
"sync/atomic"
"time"
@ -411,7 +412,12 @@ func (r *Relay) PrepareSubscription(ctx context.Context, filters Filters, opts .
for _, opt := range opts {
switch o := opt.(type) {
case WithLabel:
sub.label = string(o)
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)
}
}