@@ -142,7 +142,7 @@ instance StoreQueueClass q => QueueStoreClass q (PostgresQueueStore q) where
142142
143143 getEntityCounts :: PostgresQueueStore q -> IO EntityCounts
144144 getEntityCounts st =
145- withConnection (dbStore st) $ \ db -> do
145+ withTransaction (dbStore st) $ \ db -> do
146146 (queueCount, notifierCount, rcvServiceCount, ntfServiceCount, rcvServiceQueuesCount, ntfServiceQueuesCount) : _ <-
147147 DB. query
148148 db
@@ -496,7 +496,7 @@ instance StoreQueueClass q => QueueStoreClass q (PostgresQueueStore q) where
496496
497497batchInsertServices :: [STMService ] -> PostgresQueueStore q -> IO Int64
498498batchInsertServices services' toStore =
499- withConnection (dbStore toStore) $ \ db ->
499+ withTransaction (dbStore toStore) $ \ db ->
500500 DB. executeMany db insertServiceQuery $ map (serviceRecToRow . serviceRec) services'
501501
502502batchInsertQueues :: StoreQueueClass q => Bool -> M. Map RecipientId q -> PostgresQueueStore q' -> IO Int64
@@ -505,7 +505,7 @@ batchInsertQueues tty queues toStore = do
505505 putStrLn $ " Importing " <> show (length qs) <> " queues..."
506506 let st = dbStore toStore
507507 count <-
508- withConnection st $ \ db -> do
508+ withTransaction st $ \ db -> do
509509 DB. copy_
510510 db
511511 [sql |
@@ -514,7 +514,7 @@ batchInsertQueues tty queues toStore = do
514514 |]
515515 mapM_ (putQueue db) (zip [1 .. ] qs)
516516 DB. putCopyEnd db
517- Only qCnt : _ <- withConnection st (`DB.query_` " SELECT count(*) FROM msg_queues" )
517+ Only qCnt : _ <- withTransaction st (`DB.query_` " SELECT count(*) FROM msg_queues" )
518518 putStrLn $ progress count
519519 pure qCnt
520520 where
@@ -541,13 +541,13 @@ insertServiceQuery =
541541
542542foldServiceRecs :: forall a q . Monoid a => PostgresQueueStore q -> (ServiceRec -> IO a ) -> IO a
543543foldServiceRecs st f =
544- withConnection (dbStore st) $ \ db ->
544+ withTransaction (dbStore st) $ \ db ->
545545 DB. fold_ db " SELECT service_id, service_role, service_cert, service_cert_hash, created_at FROM services" mempty $
546546 \ ! acc -> fmap (acc <> ) . f . rowToServiceRec
547547
548548foldQueueRecs :: forall a q . Monoid a => Bool -> Bool -> PostgresQueueStore q -> Maybe Int64 -> ((RecipientId , QueueRec ) -> IO a ) -> IO a
549549foldQueueRecs tty withData st skipOld_ f = do
550- (n, r) <- withConnection (dbStore st) $ \ db ->
550+ (n, r) <- withTransaction (dbStore st) $ \ db ->
551551 foldRecs db (0 :: Int , mempty ) $ \ (i, acc) qr -> do
552552 r <- f qr
553553 let ! i' = i + 1
@@ -686,7 +686,7 @@ withDB' op st action = withDB op st $ fmap Right . action
686686
687687withDB :: forall a q . Text -> PostgresQueueStore q -> (DB. Connection -> IO (Either ErrorType a )) -> ExceptT ErrorType IO a
688688withDB op st action =
689- ExceptT $ E. try (withConnection (dbStore st) action) >>= either logErr pure
689+ ExceptT $ E. try (withTransaction (dbStore st) action) >>= either logErr pure
690690 where
691691 logErr :: E. SomeException -> IO (Either ErrorType a )
692692 logErr e = logError (" STORE: " <> err) $> Left (STORE err)
0 commit comments