mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-10-15 21:19:56 +00:00
smp-server: remove delivered notification keys
This commit is contained in:
@@ -388,7 +388,7 @@ smpServer started cfg@ServerConfig {transports, transportConfig = tCfg, startOpt
|
||||
runDeliverNtfs ms ns' stats
|
||||
where
|
||||
runDeliverNtfs :: s -> NtfStore -> ServerStats -> IO ()
|
||||
runDeliverNtfs ms (NtfStore ns) stats = do
|
||||
runDeliverNtfs ms ns'@(NtfStore ns) stats = do
|
||||
ntfs <- M.assocs <$> readTVarIO ns
|
||||
unless (null ntfs) $
|
||||
getQueueNtfServices @(StoreQueue s) (queueStore ms) ntfs >>= \case
|
||||
@@ -400,6 +400,7 @@ smpServer started cfg@ServerConfig {transports, transportConfig = tCfg, startOpt
|
||||
cIds <- IS.toList <$> readTVarIO subClients
|
||||
forM_ cIds $ \cId -> getServerClient cId srv >>= mapM_ (deliverQueueNtfs ntfs')
|
||||
atomically $ modifyTVar' ns (`M.withoutKeys` S.fromList (map fst deleted))
|
||||
deleteEmptyNtfs ns' ntfs
|
||||
where
|
||||
deliverQueueNtfs ntfs' c@Client {ntfSubscriptions} =
|
||||
whenM (currentClient readTVarIO c) $ do
|
||||
|
||||
@@ -10,6 +10,7 @@ module Simplex.Messaging.Server.NtfStore
|
||||
storeNtf,
|
||||
deleteNtfs,
|
||||
deleteExpiredNtfs,
|
||||
deleteEmptyNtfs,
|
||||
) where
|
||||
|
||||
import Control.Concurrent.STM
|
||||
@@ -22,6 +23,7 @@ import Simplex.Messaging.Encoding.String
|
||||
import Simplex.Messaging.Protocol (EncNMsgMeta, MsgId, NotifierId)
|
||||
import Simplex.Messaging.TMap (TMap)
|
||||
import qualified Simplex.Messaging.TMap as TM
|
||||
import Simplex.Messaging.Util (whenM)
|
||||
|
||||
newtype NtfStore = NtfStore (TMap NotifierId (TVar [MsgNtf]))
|
||||
|
||||
@@ -57,6 +59,14 @@ deleteExpiredNtfs (NtfStore ns) old =
|
||||
else writeTVar v ntfs' >> pure (length ntfs - length ntfs')
|
||||
| otherwise -> pure 0
|
||||
|
||||
deleteEmptyNtfs :: NtfStore -> [(NotifierId, TVar [MsgNtf])] -> IO ()
|
||||
deleteEmptyNtfs (NtfStore ns) = mapM_ deleteEmpty
|
||||
where
|
||||
deleteEmpty (nId, v) =
|
||||
whenM (null <$> readTVarIO v) $
|
||||
atomically $
|
||||
TM.lookup nId ns >>= mapM_ (\v' -> whenM (null <$> readTVar v') $ TM.delete nId ns)
|
||||
|
||||
data NtfLogRecord = NLRv1 NotifierId MsgNtf
|
||||
|
||||
instance StrEncoding MsgNtf where
|
||||
|
||||
Reference in New Issue
Block a user