user no stays in cache forever, fix some hubs bugs and add new enpoints

This commit is contained in:
2026-05-04 14:03:02 +02:00
parent 22e2d18810
commit 015c79bf09
14 changed files with 260 additions and 34 deletions
+39
View File
@@ -36,6 +36,45 @@ func getUserByToken(ctx context.Context, token string) (*types.User, error) {
return getUserById(ctx, userId)
}
func getConnection(ctx context.Context, connectionIdStr string, user *types.User) (*types.Connection, bool) {
connectionId, err := convertions.StringToUuid(connectionIdStr)
if err != nil {
return nil, false
}
if conn, ok := cache.GetConnection(user, connectionId); ok {
return conn, true
}
conn, err := postgresql.ConnectionGetById(ctx, connectionId)
if err != nil {
return nil, false
}
if conn.RequestorId != user.Id && conn.RecipientId != user.Id {
return nil, false
}
user.Mu.Lock()
user.Connections[conn.Id] = conn
user.Mu.Unlock()
return conn, true
}
func getChannelFromUser(user *types.User, channelIdStr string) (*types.HubChannel, bool) {
channelId, err := convertions.StringToUuid(channelIdStr)
if err != nil {
return nil, false
}
user.Mu.RLock()
defer user.Mu.RUnlock()
for _, hub := range user.Hubs {
hub.Mu.RLock()
ch, ok := hub.Channels[channelId]
hub.Mu.RUnlock()
if ok {
return ch, true
}
}
return nil, false
}
func getConnectionWithResponseOnFail(response http.ResponseWriter, connectionIdStr string, user *types.User) (*types.Connection, bool) {
connectionId, err := convertions.StringToUuid(connectionIdStr)
if err != nil {