Skip to content

Commit c892862

Browse files
authored
ntf server: do not log subscription status updates on subscribing/unsubscribing (#1574)
1 parent b47d28a commit c892862

File tree

1 file changed

+17
-23
lines changed
  • src/Simplex/Messaging/Notifications/Server/Store

1 file changed

+17
-23
lines changed

src/Simplex/Messaging/Notifications/Server/Store/Postgres.hs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,11 @@ updateSrvSubStatus st q status =
493493
batchUpdateSrvSubStatus :: NtfPostgresStore -> SMPServer -> Maybe ServiceId -> NonEmpty NotifierId -> NtfSubStatus -> IO Int
494494
batchUpdateSrvSubStatus st srv newServiceId nIds status =
495495
fmap (fromRight (-1)) $ withDB "batchUpdateSrvSubStatus" st $ \db -> runExceptT $ do
496-
(srvId, currServiceId) <- ExceptT $ getSMPServerService db
496+
(srvId :: Int64, currServiceId) <- ExceptT $ getSMPServerService db
497497
unless (currServiceId == newServiceId) $ liftIO $ void $
498498
DB.execute db "UPDATE smp_servers SET ntf_service_id = ? WHERE smp_server_id = ?" (newServiceId, srvId)
499499
let params = L.toList $ L.map (srvId,isJust newServiceId,status,) nIds
500-
batchUpdateStatus_ st db params
500+
liftIO $ fromIntegral <$> DB.executeMany db updateSubStatusQuery params
501501
where
502502
getSMPServerService db =
503503
firstRow id AUTH $
@@ -514,9 +514,11 @@ batchUpdateSrvSubStatus st srv newServiceId nIds status =
514514
batchUpdateSrvSubErrors :: NtfPostgresStore -> SMPServer -> NonEmpty (NotifierId, NtfSubStatus) -> IO Int
515515
batchUpdateSrvSubErrors st srv subs =
516516
fmap (fromRight (-1)) $ withDB "batchUpdateSrvSubErrors" st $ \db -> runExceptT $ do
517-
srvId <- ExceptT $ getSMPServerId db
518-
let params = L.toList $ L.map (\(nId, status) -> (srvId, False, status, nId)) subs
519-
batchUpdateStatus_ st db params
517+
srvId :: Int64 <- ExceptT $ getSMPServerId db
518+
let params = map (\(nId, status) -> (srvId, False, status, nId)) $ L.toList subs
519+
subs' <- liftIO $ DB.returning db (updateSubStatusQuery <> " RETURNING s.subscription_id, s.status, s.ntf_service_assoc") params
520+
withLog "batchUpdateStatus_" st $ forM_ subs' . logSubscriptionStatus
521+
pure $ length subs'
520522
where
521523
getSMPServerId db =
522524
firstRow fromOnly AUTH $
@@ -529,24 +531,16 @@ batchUpdateSrvSubErrors st srv subs =
529531
|]
530532
(srvToRow srv)
531533

532-
batchUpdateStatus_ :: NtfPostgresStore -> DB.Connection -> [(Int64, NtfAssociatedService, NtfSubStatus, NotifierId)] -> ExceptT ErrorType IO Int
533-
batchUpdateStatus_ st db params = do
534-
subs <-
535-
liftIO $
536-
DB.returning
537-
db
538-
[sql|
539-
UPDATE subscriptions s
540-
SET status = upd.status, ntf_service_assoc = upd.ntf_service_assoc
541-
FROM (VALUES(?, ?, ?, ?)) AS upd(smp_server_id, ntf_service_assoc, status, smp_notifier_id)
542-
WHERE s.smp_server_id = upd.smp_server_id
543-
AND s.smp_notifier_id = (upd.smp_notifier_id :: BYTEA)
544-
AND (s.status != upd.status OR s.ntf_service_assoc != upd.ntf_service_assoc)
545-
RETURNING s.subscription_id, s.status, s.ntf_service_assoc
546-
|]
547-
params
548-
withLog "batchUpdateStatus_" st $ forM_ subs . logSubscriptionStatus
549-
pure $ length subs
534+
updateSubStatusQuery :: Query
535+
updateSubStatusQuery =
536+
[sql|
537+
UPDATE subscriptions s
538+
SET status = upd.status, ntf_service_assoc = upd.ntf_service_assoc
539+
FROM (VALUES(?, ?, ?, ?)) AS upd(smp_server_id, ntf_service_assoc, status, smp_notifier_id)
540+
WHERE s.smp_server_id = upd.smp_server_id
541+
AND s.smp_notifier_id = (upd.smp_notifier_id :: BYTEA)
542+
AND (s.status != upd.status OR s.ntf_service_assoc != upd.ntf_service_assoc)
543+
|]
550544

551545
removeServiceAssociation :: NtfPostgresStore -> SMPServer -> IO (Either ErrorType (Int64, Int))
552546
removeServiceAssociation st srv = do

0 commit comments

Comments
 (0)