getAgentSubsSummary

This commit is contained in:
spaced4ndy
2024-06-26 12:08:58 +04:00
parent 65e5cece1e
commit b59aa8c3f4
2 changed files with 11 additions and 0 deletions
+1
View File
@@ -106,6 +106,7 @@ module Simplex.Messaging.Agent
rcDiscoverCtrl,
getAgentServersSummary,
resetAgentServersStats,
getAgentSubsSummary,
foregroundAgent,
suspendAgent,
execAgentStoreSQL,
+10
View File
@@ -93,6 +93,7 @@ module Simplex.Messaging.Agent.Client
ServerSessions (..),
SMPServerSubs (..),
getAgentServersSummary,
getAgentSubsSummary,
getAgentSubscriptions,
slowNetworkConfig,
protocolClientError,
@@ -1997,6 +1998,15 @@ data ServerSessions = ServerSessions
}
deriving (Show)
getAgentSubsSummary :: AgentClient -> IO (Map UserId SMPServerSubs)
getAgentSubsSummary c = do
subs <- M.foldrWithKey' (addSub incActive) M.empty <$> readTVarIO (getRcvQueues $ activeSubs c)
M.foldrWithKey' (addSub incPending) subs <$> readTVarIO (getRcvQueues $ pendingSubs c)
where
addSub f (userId, _, _) _ = M.alter (Just . f . fromMaybe SMPServerSubs {ssActive = 0, ssPending = 0}) userId
incActive ss = ss {ssActive = ssActive ss + 1}
incPending ss = ss {ssPending = ssPending ss + 1}
getAgentServersSummary :: AgentClient -> IO AgentServersSummary
getAgentServersSummary c@AgentClient {smpServersStats, xftpServersStats, srvStatsStartedAt, agentEnv} = do
sss <- mapM getAgentSMPServerStats =<< readTVarIO smpServersStats