remove unused logging, improve concurrency, and minor fixes

- pkg/protocol/socketapi/publisher.go
  - Removed unnecessary debug logging for subscriber filtering and privilege checks.
  - Minor comment formatting correction.

- pkg/database/query-events.go
  - Removed outdated debug logs during event processing.
  - Cleaned up redundant log usage for deletion event handling.

- pkg/app/relay/lists.go
  - Replaced `sync.Mutex` with `sync.RWMutex` for better concurrency handling.
  - Adjusted locking methods (`Lock` to `RLock` and `Unlock` to `RUnlock`) where applicable.
This commit is contained in:
2025-08-18 13:28:14 +01:00
parent b8bdaa95c5
commit b8a12d7a11
3 changed files with 10 additions and 92 deletions

View File

@@ -16,7 +16,7 @@ import (
// separate from the ownersFollowed list, but there could be reasons for this
// distinction, such as rate limiting applying to the former and not the latter.
type Lists struct {
sync.Mutex
sync.RWMutex
ownersPubkeys [][]byte
ownersFollowed [][]byte
followedFollows [][]byte
@@ -24,14 +24,14 @@ type Lists struct {
}
func (l *Lists) LenOwnersPubkeys() (ll int) {
l.Lock()
l.RLock()
defer l.Unlock()
ll = len(l.ownersPubkeys)
return
}
func (l *Lists) OwnersPubkeys() (pks [][]byte) {
l.Lock()
l.RLock()
defer l.Unlock()
pks = append(pks, l.ownersPubkeys...)
return
@@ -45,14 +45,14 @@ func (l *Lists) SetOwnersPubkeys(pks [][]byte) {
}
func (l *Lists) LenOwnersFollowed() (ll int) {
l.Lock()
l.RLock()
defer l.Unlock()
ll = len(l.ownersFollowed)
return
}
func (l *Lists) OwnersFollowed() (pks [][]byte) {
l.Lock()
l.RLock()
defer l.Unlock()
pks = append(pks, l.ownersFollowed...)
return
@@ -66,14 +66,14 @@ func (l *Lists) SetOwnersFollowed(pks [][]byte) {
}
func (l *Lists) LenFollowedFollows() (ll int) {
l.Lock()
l.RLock()
defer l.Unlock()
ll = len(l.followedFollows)
return
}
func (l *Lists) FollowedFollows() (pks [][]byte) {
l.Lock()
l.RLock()
defer l.Unlock()
pks = append(pks, l.followedFollows...)
return
@@ -87,14 +87,14 @@ func (l *Lists) SetFollowedFollows(pks [][]byte) {
}
func (l *Lists) LenOwnersMuted() (ll int) {
l.Lock()
l.RLock()
defer l.Unlock()
ll = len(l.ownersMuted)
return
}
func (l *Lists) OwnersMuted() (pks [][]byte) {
l.Lock()
l.RLock()
defer l.Unlock()
pks = append(pks, l.ownersMuted...)
return

View File

@@ -2,7 +2,6 @@ package database
import (
"bytes"
"fmt"
"orly.dev/pkg/crypto/sha256"
"orly.dev/pkg/database/indexes/types"
"orly.dev/pkg/encoders/event"
@@ -105,14 +104,6 @@ func (d *D) QueryEvents(c context.T, f *filter.F) (evs event.S, err error) {
idPkTs = append(idPkTs, deletionIdPkTs...)
}
// First pass: collect all deletion events
log.T.C(
func() string {
return fmt.Sprintf(
"Debug: Starting first pass - processing %d events\n",
len(idPkTs),
)
},
)
for _, idpk := range idPkTs {
var ev *event.E
ser := new(types.Uint40)
@@ -130,14 +121,6 @@ func (d *D) QueryEvents(c context.T, f *filter.F) (evs event.S, err error) {
}
// Process deletion events to build our deletion maps
if ev.Kind.Equal(kind.Deletion) {
log.T.C(
func() string {
return fmt.Sprintf(
"found deletion event with ID: %s\n",
hex.Enc(ev.ID),
)
},
)
// Check for 'e' tags that directly reference event IDs
eTags := ev.Tags.GetAll(tag.New([]byte{'e'}))
for _, eTag := range eTags.ToSliceOfTags() {
@@ -149,22 +132,7 @@ func (d *D) QueryEvents(c context.T, f *filter.F) (evs event.S, err error) {
}
// Check for 'a' tags that reference parameterized replaceable
// events
log.T.C(
func() string {
return fmt.Sprintf(
"processing deletion event with ID: %s\n",
hex.Enc(ev.ID),
)
},
)
aTags := ev.Tags.GetAll(tag.New([]byte{'a'}))
log.D.C(
func() string {
return fmt.Sprintf(
"Found %d a-tags\n", aTags.Len(),
)
},
)
for _, aTag := range aTags.ToSliceOfTags() {
if aTag.Len() < 2 {
continue
@@ -205,21 +173,6 @@ func (d *D) QueryEvents(c context.T, f *filter.F) (evs event.S, err error) {
dValue := string(split[2])
deletionsByKindPubkeyDTag[key][dValue] = true
// Debug logging
log.D.C(
func() string {
return fmt.Sprintf(
"processing a-tag: %s\n", string(aTag.Value()),
)
},
)
log.D.C(
func() string {
return fmt.Sprintf(
"adding to deletion map - key: %s, d-tag: %s\n",
key, dValue,
)
},
)
}
// For replaceable events, we need to check if there are any
// e-tags that reference events with the same kind and pubkey
@@ -353,23 +306,6 @@ func (d *D) QueryEvents(c context.T, f *filter.F) (evs event.S, err error) {
// Check if this event has been deleted via an a-tag
if deletionMap, exists := deletionsByKindPubkeyDTag[key]; exists {
// Debug logging
log.T.C(
func() string {
return fmt.Sprintf(
"Checking deletion map - key: %s, d-tag: %s",
key, dValue,
)
},
)
log.T.C(
func() string {
return fmt.Sprintf(
"Deletion map contains key: %v, d-tag in map: %v",
exists, deletionMap[dValue],
)
},
)
// If the d-tag value is in the deletion map and this event
// is not specifically requested by ID, skip it
if deletionMap[dValue] && !isIdInFilter {

View File

@@ -140,7 +140,7 @@ func (p *S) Receive(msg typer.T) {
// # Expected behaviour
//
// Delivers the event to all subscribers whose filters match the event. It
// applies authentication checks if required by the server, and skips delivery
// applies authentication checks if required by the server and skips delivery
// for unauthenticated users when events are privileged.
func (p *S) Deliver(ev *event.E) {
var err error
@@ -163,29 +163,11 @@ func (p *S) Deliver(ev *event.E) {
},
)
for id, subscriber := range subs {
log.T.F(
"subscriber %s\n%s", w.RealRemote(),
subscriber.Marshal(nil),
)
if !subscriber.Match(ev) {
log.T.C(
func() string {
return fmt.Sprintf(
"subscriber %s filter %s not match", id,
subscriber.Marshal(nil),
)
},
)
continue
}
if p.Server.AuthRequired() {
if !auth.CheckPrivilege(w.AuthedPubkey(), ev) {
log.W.F(
"not privileged %0x ev pubkey %0x ev pubkey %0x kind %s privileged: %v",
w.AuthedPubkey(), ev.Pubkey,
w.AuthedPubkey(), ev.Kind.Name(),
ev.Kind.IsPrivileged(),
)
continue
}
var res *eventenvelope.Result