Refactor publisher to clean up dead code, streamline event filtering, and optimize subscriber removal logic.

This commit is contained in:
2025-09-07 23:35:01 +01:00
parent 9dec51cd40
commit ebb5e2c0f3

View File

@@ -8,6 +8,7 @@ import (
"encoders.orly/envelopes/eventenvelope" "encoders.orly/envelopes/eventenvelope"
"encoders.orly/event" "encoders.orly/event"
"encoders.orly/filter" "encoders.orly/filter"
"encoders.orly/kind"
"github.com/coder/websocket" "github.com/coder/websocket"
"interfaces.orly/publisher" "interfaces.orly/publisher"
"interfaces.orly/typer" "interfaces.orly/typer"
@@ -165,11 +166,9 @@ func (p *P) Deliver(ev *event.E) {
if !subscriber.Match(ev) { if !subscriber.Match(ev) {
continue continue
} }
// if p.Server.AuthRequired() { if kind.IsPrivileged(ev.Kind) {
// if !auth.CheckPrivilege(w.AuthedPubkey(), ev) {
// continue }
// }
// }
var res *eventenvelope.Result var res *eventenvelope.Result
if res, err = eventenvelope.NewResultWith(id, ev); chk.E(err) { if res, err = eventenvelope.NewResultWith(id, ev); chk.E(err) {
continue continue
@@ -198,7 +197,6 @@ func (p *P) Deliver(ev *event.E) {
// removeSubscriberId removes a specific subscription from a subscriber // removeSubscriberId removes a specific subscription from a subscriber
// websocket. // websocket.
func (p *P) removeSubscriberId(ws *websocket.Conn, id string) { func (p *P) removeSubscriberId(ws *websocket.Conn, id string) {
p.Mx.Lock()
var subs map[string]Subscription var subs map[string]Subscription
var ok bool var ok bool
if subs, ok = p.Map[ws]; ok { if subs, ok = p.Map[ws]; ok {
@@ -208,13 +206,10 @@ func (p *P) removeSubscriberId(ws *websocket.Conn, id string) {
delete(p.Map, ws) delete(p.Map, ws)
} }
} }
p.Mx.Unlock()
} }
// removeSubscriber removes a websocket from the P collection. // removeSubscriber removes a websocket from the P collection.
func (p *P) removeSubscriber(ws *websocket.Conn) { func (p *P) removeSubscriber(ws *websocket.Conn) {
p.Mx.Lock()
clear(p.Map[ws]) clear(p.Map[ws])
delete(p.Map, ws) delete(p.Map, ws)
p.Mx.Unlock()
} }