mirror of
https://github.com/signaller-matrix/signaller.git
synced 2024-11-25 03:42:20 +00:00
Switch backend mutex to RW mutex
This commit is contained in:
parent
1e87bcac8b
commit
3185bda38e
@ -18,7 +18,7 @@ type Backend struct {
|
|||||||
rooms map[string]internal.Room
|
rooms map[string]internal.Room
|
||||||
hostname string
|
hostname string
|
||||||
validateUsernameFunc func(string) error // TODO: create ability to redefine validation func
|
validateUsernameFunc func(string) error // TODO: create ability to redefine validation func
|
||||||
mutex sync.Mutex // TODO: replace with RW mutex
|
mutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type Token struct {
|
type Token struct {
|
||||||
@ -88,8 +88,8 @@ func (backend *Backend) Sync(token string, request mSync.SyncRequest) (response
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (backend *Backend) GetUserByToken(token string) internal.User {
|
func (backend *Backend) GetUserByToken(token string) internal.User {
|
||||||
backend.mutex.Lock()
|
backend.mutex.RLock()
|
||||||
defer backend.mutex.Unlock()
|
defer backend.mutex.RUnlock()
|
||||||
|
|
||||||
for _, user := range backend.data {
|
for _, user := range backend.data {
|
||||||
for userToken := range user.(*User).Tokens {
|
for userToken := range user.(*User).Tokens {
|
||||||
@ -103,8 +103,8 @@ func (backend *Backend) GetUserByToken(token string) internal.User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (backend *Backend) GetRoomByID(id string) internal.Room {
|
func (backend *Backend) GetRoomByID(id string) internal.Room {
|
||||||
backend.mutex.Lock()
|
backend.mutex.RLock()
|
||||||
defer backend.mutex.Unlock()
|
defer backend.mutex.RUnlock()
|
||||||
|
|
||||||
for roomID, room := range backend.rooms {
|
for roomID, room := range backend.rooms {
|
||||||
if roomID == id {
|
if roomID == id {
|
||||||
@ -116,8 +116,8 @@ func (backend *Backend) GetRoomByID(id string) internal.Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (backend *Backend) GetUserByName(userName string) internal.User {
|
func (backend *Backend) GetUserByName(userName string) internal.User {
|
||||||
backend.mutex.Lock()
|
backend.mutex.RLock()
|
||||||
defer backend.mutex.Unlock()
|
defer backend.mutex.RUnlock()
|
||||||
|
|
||||||
if user, exists := backend.data[userName]; exists {
|
if user, exists := backend.data[userName]; exists {
|
||||||
return user
|
return user
|
||||||
@ -127,8 +127,8 @@ func (backend *Backend) GetUserByName(userName string) internal.User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (backend *Backend) PublicRooms(filter string) []internal.Room {
|
func (backend *Backend) PublicRooms(filter string) []internal.Room {
|
||||||
backend.mutex.Lock()
|
backend.mutex.RLock()
|
||||||
defer backend.mutex.Unlock()
|
defer backend.mutex.RUnlock()
|
||||||
|
|
||||||
var rooms []internal.Room
|
var rooms []internal.Room
|
||||||
|
|
||||||
@ -147,8 +147,8 @@ func (backend *Backend) PublicRooms(filter string) []internal.Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (backend *Backend) ValidateUsernameFunc() func(string) error {
|
func (backend *Backend) ValidateUsernameFunc() func(string) error {
|
||||||
backend.mutex.Lock()
|
backend.mutex.RLock()
|
||||||
defer backend.mutex.Unlock()
|
defer backend.mutex.RUnlock()
|
||||||
|
|
||||||
return backend.validateUsernameFunc
|
return backend.validateUsernameFunc
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user