dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 36d4f0afa2dd37e2ea9638c86c106f5c5d185aad
parent a20c11b64e2659e326b07c8a0cda7b60ab4c5fff
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 12 Jun 2023 08:52:43 -0700

improve perf

Diffstat:
Mpkg/web/handlers/handlers.go | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -5256,7 +5256,7 @@ func (m *UserStreamsMap) Count() (out int64) { // If the limit is reached, the pages will then refuse to load. // This is to prevent a malicious user from opening unlimited amount of streams and wasting the server resources. type UsersStreamsManager struct { - sync.Mutex + sync.RWMutex m map[database.UserID]UserStreamsMap } @@ -5289,8 +5289,8 @@ func (m *UsersStreamsManager) Remove(userID database.UserID, chessKey string) { } func (m *UsersStreamsManager) GetUserStreamsCountFor(userID database.UserID, key string) (out int64) { - m.Lock() - defer m.Unlock() + m.RLock() + defer m.RUnlock() if userMap, found := m.m[userID]; found { if nbStreams, found1 := userMap[key]; found1 { return nbStreams @@ -5300,8 +5300,8 @@ func (m *UsersStreamsManager) GetUserStreamsCountFor(userID database.UserID, key } func (m *UsersStreamsManager) GetUsers() (out []database.UserID) { - m.Lock() - defer m.Unlock() + m.RLock() + defer m.RUnlock() for userID, userMap := range m.m { if userMap.Count() > 0 { out = append(out, userID)