Files
orly/pkg/app/relay/lists.go
mleku af1e898191 fix: correct RWMutex usage in relay lists for proper concurrency handling
- pkg/app/relay/lists.go
  - Replaced incorrect `Unlock` calls with `RUnlock` in read operations.
2025-08-18 13:34:01 +01:00

109 lines
2.2 KiB
Go

package relay
import (
"sync"
)
// Lists manages lists of pubkeys, followed users, follows, and muted users with
// concurrency safety via a mutex.
//
// This list is designed primarily for owner-follow-list in mind, but with an
// explicit allowlist/blocklist set up, ownersFollowed corresponds to the
// allowed users, and ownersMuted corresponds to the blocked users, and all
// filtering logic will work the same way.
//
// Currently, there is no explicit purpose for the followedFollows list being
// 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.RWMutex
ownersPubkeys [][]byte
ownersFollowed [][]byte
followedFollows [][]byte
ownersMuted [][]byte
}
func (l *Lists) LenOwnersPubkeys() (ll int) {
l.RLock()
defer l.RUnlock()
ll = len(l.ownersPubkeys)
return
}
func (l *Lists) OwnersPubkeys() (pks [][]byte) {
l.RLock()
defer l.RUnlock()
pks = append(pks, l.ownersPubkeys...)
return
}
func (l *Lists) SetOwnersPubkeys(pks [][]byte) {
l.Lock()
defer l.Unlock()
l.ownersPubkeys = pks
return
}
func (l *Lists) LenOwnersFollowed() (ll int) {
l.RLock()
defer l.RUnlock()
ll = len(l.ownersFollowed)
return
}
func (l *Lists) OwnersFollowed() (pks [][]byte) {
l.RLock()
defer l.RUnlock()
pks = append(pks, l.ownersFollowed...)
return
}
func (l *Lists) SetOwnersFollowed(pks [][]byte) {
l.Lock()
defer l.Unlock()
l.ownersFollowed = pks
return
}
func (l *Lists) LenFollowedFollows() (ll int) {
l.RLock()
defer l.RUnlock()
ll = len(l.followedFollows)
return
}
func (l *Lists) FollowedFollows() (pks [][]byte) {
l.RLock()
defer l.RUnlock()
pks = append(pks, l.followedFollows...)
return
}
func (l *Lists) SetFollowedFollows(pks [][]byte) {
l.Lock()
defer l.Unlock()
l.followedFollows = pks
return
}
func (l *Lists) LenOwnersMuted() (ll int) {
l.RLock()
defer l.RUnlock()
ll = len(l.ownersMuted)
return
}
func (l *Lists) OwnersMuted() (pks [][]byte) {
l.RLock()
defer l.RUnlock()
pks = append(pks, l.ownersMuted...)
return
}
func (l *Lists) SetOwnersMuted(pks [][]byte) {
l.Lock()
defer l.Unlock()
l.ownersMuted = pks
return
}