@@ -43,14 +43,13 @@ import qualified Data.ByteString.Builder as BB
43
43
import Data.ByteString.Char8 (ByteString )
44
44
import qualified Data.ByteString.Lazy as LB
45
45
import Data.Bitraversable (bimapM )
46
- import Data.Either (fromRight , lefts , rights )
46
+ import Data.Either (fromRight , lefts )
47
47
import Data.Functor (($>) )
48
48
import Data.Int (Int64 )
49
49
import Data.List (foldl' , intersperse , partition )
50
50
import Data.List.NonEmpty (NonEmpty )
51
- import qualified Data.List.NonEmpty as L
52
51
import qualified Data.Map.Strict as M
53
- import Data.Maybe (catMaybes , fromMaybe , mapMaybe )
52
+ import Data.Maybe (catMaybes , fromMaybe )
54
53
import qualified Data.Set as S
55
54
import Data.Text (Text )
56
55
import Data.Text.Encoding (decodeLatin1 , encodeUtf8 )
@@ -65,7 +64,7 @@ import Database.PostgreSQL.Simple.ToField (Action (..), ToField (..))
65
64
import Database.PostgreSQL.Simple.Errors (ConstraintViolation (.. ), constraintViolation )
66
65
import Database.PostgreSQL.Simple.SqlQQ (sql )
67
66
import GHC.IO (catchAny )
68
- import Simplex.Messaging.Agent.Client (withLockMap , withLocksMap )
67
+ import Simplex.Messaging.Agent.Client (withLockMap )
69
68
import Simplex.Messaging.Agent.Lock (Lock )
70
69
import Simplex.Messaging.Agent.Store.AgentStore ()
71
70
import Simplex.Messaging.Agent.Store.Postgres (createDBStore , closeDBStore )
@@ -84,7 +83,7 @@ import Simplex.Messaging.Server.StoreLog
84
83
import Simplex.Messaging.TMap (TMap )
85
84
import qualified Simplex.Messaging.TMap as TM
86
85
import Simplex.Messaging.Transport (SMPServiceRole (.. ))
87
- import Simplex.Messaging.Util (eitherToMaybe , firstRow , ifM , maybeFirstRow , tshow , (<$$>) , ($>>=) )
86
+ import Simplex.Messaging.Util (eitherToMaybe , firstRow , ifM , maybeFirstRow , tshow , (<$$>) )
88
87
import System.Exit (exitFailure )
89
88
import System.IO (IOMode (.. ), hFlush , stdout )
90
89
import UnliftIO.STM
@@ -485,11 +484,15 @@ instance StoreQueueClass q => QueueStoreClass q (PostgresQueueStore q) where
485
484
let (sNtfs, restNtfs) = partition (\ (nId, _) -> S. member nId snIds) ntfs'
486
485
in ((serviceId, sNtfs) : ssNtfs, restNtfs)
487
486
488
- getNtfServiceQueueCount :: PostgresQueueStore q -> ServiceId -> IO (Either ErrorType Int64 )
489
- getNtfServiceQueueCount st serviceId =
490
- E. uninterruptibleMask_ $ runExceptT $ withDB' " getNtfServiceQueueCount " st $ \ db ->
487
+ getServiceQueueCount :: ( PartyI p , ServiceParty p ) => PostgresQueueStore q -> SParty p -> ServiceId -> IO (Either ErrorType Int64 )
488
+ getServiceQueueCount st party serviceId =
489
+ E. uninterruptibleMask_ $ runExceptT $ withDB' " getServiceQueueCount " st $ \ db ->
491
490
fmap (fromMaybe 0 ) $ maybeFirstRow fromOnly $
492
- DB. query db " SELECT count(1) FROM msg_queues WHERE ntf_service_id = ? AND deleted_at IS NULL" (Only serviceId)
491
+ DB. query db query (Only serviceId)
492
+ where
493
+ query = case party of
494
+ SRecipientService -> " SELECT count(1) FROM msg_queues WHERE rcv_service_id = ? AND deleted_at IS NULL"
495
+ SNotifierService -> " SELECT count(1) FROM msg_queues WHERE ntf_service_id = ? AND deleted_at IS NULL"
493
496
494
497
batchInsertServices :: [STMService ] -> PostgresQueueStore q -> IO Int64
495
498
batchInsertServices services' toStore =
0 commit comments