@@ -143,7 +143,7 @@ instance StoreQueueClass q => QueueStoreClass q (PostgresQueueStore q) where
143143
144144 getEntityCounts :: PostgresQueueStore q -> IO EntityCounts
145145 getEntityCounts st =
146- withConnection (dbStore st) $ \ db -> do
146+ withTransaction (dbStore st) $ \ db -> do
147147 (queueCount, notifierCount, rcvServiceCount, ntfServiceCount, rcvServiceQueuesCount, ntfServiceQueuesCount) : _ <-
148148 DB. query
149149 db
@@ -497,7 +497,7 @@ instance StoreQueueClass q => QueueStoreClass q (PostgresQueueStore q) where
497497
498498batchInsertServices :: [STMService ] -> PostgresQueueStore q -> IO Int64
499499batchInsertServices services' toStore =
500- withConnection (dbStore toStore) $ \ db ->
500+ withTransaction (dbStore toStore) $ \ db ->
501501 DB. executeMany db insertServiceQuery $ map (serviceRecToRow . serviceRec) services'
502502
503503batchInsertQueues :: StoreQueueClass q => Bool -> M. Map RecipientId q -> PostgresQueueStore q' -> IO Int64
@@ -506,7 +506,7 @@ batchInsertQueues tty queues toStore = do
506506 putStrLn $ " Importing " <> show (length qs) <> " queues..."
507507 let st = dbStore toStore
508508 count <-
509- withConnection st $ \ db -> do
509+ withTransaction st $ \ db -> do
510510 DB. copy_
511511 db
512512 [sql |
@@ -515,7 +515,7 @@ batchInsertQueues tty queues toStore = do
515515 |]
516516 mapM_ (putQueue db) (zip [1 .. ] qs)
517517 DB. putCopyEnd db
518- Only qCnt : _ <- withConnection st (`DB.query_` " SELECT count(*) FROM msg_queues" )
518+ Only qCnt : _ <- withTransaction st (`DB.query_` " SELECT count(*) FROM msg_queues" )
519519 putStrLn $ progress count
520520 pure qCnt
521521 where
@@ -542,7 +542,7 @@ insertServiceQuery =
542542
543543foldServiceRecs :: Monoid a => PostgresQueueStore q -> (ServiceRec -> IO a ) -> IO a
544544foldServiceRecs st f =
545- withConnection (dbStore st) $ \ db ->
545+ withTransaction (dbStore st) $ \ db ->
546546 DB. fold_ db " SELECT service_id, service_role, service_cert, service_cert_hash, created_at FROM services" mempty $
547547 \ ! acc -> fmap (acc <> ) . f . rowToServiceRec
548548
@@ -553,7 +553,7 @@ foldRcvServiceQueueRecs st serviceId f acc =
553553
554554foldQueueRecs :: Monoid a => Bool -> Bool -> PostgresQueueStore q -> Maybe Int64 -> ((RecipientId , QueueRec ) -> IO a ) -> IO a
555555foldQueueRecs tty withData st skipOld_ f = do
556- (n, r) <- withConnection (dbStore st) $ \ db ->
556+ (n, r) <- withTransaction (dbStore st) $ \ db ->
557557 foldRecs db (0 :: Int , mempty ) $ \ (i, acc) qr -> do
558558 r <- f qr
559559 let ! i' = i + 1
@@ -692,7 +692,7 @@ withDB' op st action = withDB op st $ fmap Right . action
692692
693693withDB :: forall a q . Text -> PostgresQueueStore q -> (DB. Connection -> IO (Either ErrorType a )) -> ExceptT ErrorType IO a
694694withDB op st action =
695- ExceptT $ E. try (withConnection (dbStore st) action) >>= either logErr pure
695+ ExceptT $ E. try (withTransaction (dbStore st) action) >>= either logErr pure
696696 where
697697 logErr :: E. SomeException -> IO (Either ErrorType a )
698698 logErr e = logError (" STORE: " <> err) $> Left (STORE err)
0 commit comments