converted the sessions map to a pointer map, removed un-needed updates and locks

This commit is contained in:
2025-11-16 09:26:04 +03:00
parent 1fff42b4e0
commit abe146f7ec
3 changed files with 2 additions and 9 deletions

View File

@@ -15,5 +15,5 @@ type Session struct {
lastInteractedPartyIsA bool
}
var openSessions = make(map[string]Session)
var openSessions = make(map[string]*Session)
var sessionsMu sync.RWMutex

View File

@@ -46,7 +46,7 @@ func createSession(w http.ResponseWriter, r *http.Request) {
}
sessionsMu.Lock()
openSessions[session.id] = session
openSessions[session.id] = &session
sessionsMu.Unlock()
fmt.Fprintf(w,

View File

@@ -43,18 +43,11 @@ func websocketSignaler(conn *websocket.Conn, partyIsA bool, sessionId string) {
}
}
sessionsMu.Lock()
openSessions[openSession.id] = openSession
sessionsMu.Unlock()
for {
msgType, msg, err := conn.ReadMessage()
if err != nil {
break
}
sessionsMu.RLock()
openSession, ok := openSessions[sessionId]
sessionsMu.RUnlock()
if !ok {
// conn.WriteMessage(1, "{Session not found or something}")