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:
@@ -16,7 +16,7 @@ import (
|
|||||||
// separate from the ownersFollowed list, but there could be reasons for this
|
// 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.
|
// distinction, such as rate limiting applying to the former and not the latter.
|
||||||
type Lists struct {
|
type Lists struct {
|
||||||
sync.Mutex
|
sync.RWMutex
|
||||||
ownersPubkeys [][]byte
|
ownersPubkeys [][]byte
|
||||||
ownersFollowed [][]byte
|
ownersFollowed [][]byte
|
||||||
followedFollows [][]byte
|
followedFollows [][]byte
|
||||||
@@ -24,14 +24,14 @@ type Lists struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Lists) LenOwnersPubkeys() (ll int) {
|
func (l *Lists) LenOwnersPubkeys() (ll int) {
|
||||||
l.Lock()
|
l.RLock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
ll = len(l.ownersPubkeys)
|
ll = len(l.ownersPubkeys)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Lists) OwnersPubkeys() (pks [][]byte) {
|
func (l *Lists) OwnersPubkeys() (pks [][]byte) {
|
||||||
l.Lock()
|
l.RLock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
pks = append(pks, l.ownersPubkeys...)
|
pks = append(pks, l.ownersPubkeys...)
|
||||||
return
|
return
|
||||||
@@ -45,14 +45,14 @@ func (l *Lists) SetOwnersPubkeys(pks [][]byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Lists) LenOwnersFollowed() (ll int) {
|
func (l *Lists) LenOwnersFollowed() (ll int) {
|
||||||
l.Lock()
|
l.RLock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
ll = len(l.ownersFollowed)
|
ll = len(l.ownersFollowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Lists) OwnersFollowed() (pks [][]byte) {
|
func (l *Lists) OwnersFollowed() (pks [][]byte) {
|
||||||
l.Lock()
|
l.RLock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
pks = append(pks, l.ownersFollowed...)
|
pks = append(pks, l.ownersFollowed...)
|
||||||
return
|
return
|
||||||
@@ -66,14 +66,14 @@ func (l *Lists) SetOwnersFollowed(pks [][]byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Lists) LenFollowedFollows() (ll int) {
|
func (l *Lists) LenFollowedFollows() (ll int) {
|
||||||
l.Lock()
|
l.RLock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
ll = len(l.followedFollows)
|
ll = len(l.followedFollows)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Lists) FollowedFollows() (pks [][]byte) {
|
func (l *Lists) FollowedFollows() (pks [][]byte) {
|
||||||
l.Lock()
|
l.RLock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
pks = append(pks, l.followedFollows...)
|
pks = append(pks, l.followedFollows...)
|
||||||
return
|
return
|
||||||
@@ -87,14 +87,14 @@ func (l *Lists) SetFollowedFollows(pks [][]byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Lists) LenOwnersMuted() (ll int) {
|
func (l *Lists) LenOwnersMuted() (ll int) {
|
||||||
l.Lock()
|
l.RLock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
ll = len(l.ownersMuted)
|
ll = len(l.ownersMuted)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Lists) OwnersMuted() (pks [][]byte) {
|
func (l *Lists) OwnersMuted() (pks [][]byte) {
|
||||||
l.Lock()
|
l.RLock()
|
||||||
defer l.Unlock()
|
defer l.Unlock()
|
||||||
pks = append(pks, l.ownersMuted...)
|
pks = append(pks, l.ownersMuted...)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"orly.dev/pkg/crypto/sha256"
|
"orly.dev/pkg/crypto/sha256"
|
||||||
"orly.dev/pkg/database/indexes/types"
|
"orly.dev/pkg/database/indexes/types"
|
||||||
"orly.dev/pkg/encoders/event"
|
"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...)
|
idPkTs = append(idPkTs, deletionIdPkTs...)
|
||||||
}
|
}
|
||||||
// First pass: collect all deletion events
|
// 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 {
|
for _, idpk := range idPkTs {
|
||||||
var ev *event.E
|
var ev *event.E
|
||||||
ser := new(types.Uint40)
|
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
|
// Process deletion events to build our deletion maps
|
||||||
if ev.Kind.Equal(kind.Deletion) {
|
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
|
// Check for 'e' tags that directly reference event IDs
|
||||||
eTags := ev.Tags.GetAll(tag.New([]byte{'e'}))
|
eTags := ev.Tags.GetAll(tag.New([]byte{'e'}))
|
||||||
for _, eTag := range eTags.ToSliceOfTags() {
|
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
|
// Check for 'a' tags that reference parameterized replaceable
|
||||||
// events
|
// 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'}))
|
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() {
|
for _, aTag := range aTags.ToSliceOfTags() {
|
||||||
if aTag.Len() < 2 {
|
if aTag.Len() < 2 {
|
||||||
continue
|
continue
|
||||||
@@ -205,21 +173,6 @@ func (d *D) QueryEvents(c context.T, f *filter.F) (evs event.S, err error) {
|
|||||||
dValue := string(split[2])
|
dValue := string(split[2])
|
||||||
deletionsByKindPubkeyDTag[key][dValue] = true
|
deletionsByKindPubkeyDTag[key][dValue] = true
|
||||||
// Debug logging
|
// 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
|
// For replaceable events, we need to check if there are any
|
||||||
// e-tags that reference events with the same kind and pubkey
|
// 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
|
// Check if this event has been deleted via an a-tag
|
||||||
if deletionMap, exists := deletionsByKindPubkeyDTag[key]; exists {
|
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
|
// If the d-tag value is in the deletion map and this event
|
||||||
// is not specifically requested by ID, skip it
|
// is not specifically requested by ID, skip it
|
||||||
if deletionMap[dValue] && !isIdInFilter {
|
if deletionMap[dValue] && !isIdInFilter {
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ func (p *S) Receive(msg typer.T) {
|
|||||||
// # Expected behaviour
|
// # Expected behaviour
|
||||||
//
|
//
|
||||||
// Delivers the event to all subscribers whose filters match the event. It
|
// 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.
|
// for unauthenticated users when events are privileged.
|
||||||
func (p *S) Deliver(ev *event.E) {
|
func (p *S) Deliver(ev *event.E) {
|
||||||
var err error
|
var err error
|
||||||
@@ -163,29 +163,11 @@ func (p *S) Deliver(ev *event.E) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
for id, subscriber := range subs {
|
for id, subscriber := range subs {
|
||||||
log.T.F(
|
|
||||||
"subscriber %s\n%s", w.RealRemote(),
|
|
||||||
subscriber.Marshal(nil),
|
|
||||||
)
|
|
||||||
if !subscriber.Match(ev) {
|
if !subscriber.Match(ev) {
|
||||||
log.T.C(
|
|
||||||
func() string {
|
|
||||||
return fmt.Sprintf(
|
|
||||||
"subscriber %s filter %s not match", id,
|
|
||||||
subscriber.Marshal(nil),
|
|
||||||
)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if p.Server.AuthRequired() {
|
if p.Server.AuthRequired() {
|
||||||
if !auth.CheckPrivilege(w.AuthedPubkey(), ev) {
|
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
|
continue
|
||||||
}
|
}
|
||||||
var res *eventenvelope.Result
|
var res *eventenvelope.Result
|
||||||
|
|||||||
Reference in New Issue
Block a user