@@ -41,6 +41,7 @@ import Data.Conduit.Process.Typed
4141 runProcess_ , getStdout , getStderr , createSource )
4242import qualified Data.Conduit.Text as CT
4343import Data.List hiding (any )
44+ import Data.List.Split (chunksOf )
4445import qualified Data.Map.Strict as M
4546import qualified Data.Map.Strict as Map
4647import qualified Data.Set as Set
@@ -584,14 +585,7 @@ executePlan' installedMap0 targets plan ee@ExecuteEnv {..} = do
584585 [] -> return ()
585586 ids -> do
586587 localDB <- packageDatabaseLocal
587- forM_ ids $ \ (id', (ident, reason)) -> do
588- logInfo $
589- fromString (packageIdentifierString ident) <>
590- " : unregistering" <>
591- if T. null reason
592- then " "
593- else " (" <> RIO. display reason <> " )"
594- unregisterGhcPkgId wc cv localDB id' ident
588+ unregisterPackages wc cv localDB ids
595589
596590 liftIO $ atomically $ modifyTVar' eeLocalDumpPkgs $ \ initMap ->
597591 foldl' (flip Map. delete) initMap $ Map. keys (planUnregisterLocal plan)
@@ -661,6 +655,35 @@ executePlan' installedMap0 targets plan ee@ExecuteEnv {..} = do
661655 $ Map. elems
662656 $ planUnregisterLocal plan
663657
658+ unregisterPackages ::
659+ (HasProcessContext env , HasLogFunc env )
660+ => WhichCompiler
661+ -> ActualCompiler
662+ -> Path Abs Dir
663+ -> [(GhcPkgId , (PackageIdentifier , Text ))]
664+ -> RIO env ()
665+ unregisterPackages wc ac localDB ids = do
666+ let logReason ident reason =
667+ logInfo $
668+ fromString (packageIdentifierString ident) <> " : unregistering" <>
669+ if T. null reason
670+ then " "
671+ else " (" <> RIO. display reason <> " )"
672+ case ac of
673+ ACGhc v | v >= mkVersion [8 , 0 , 1 ] -> do
674+ let batchSize = 500
675+ for_ (chunksOf batchSize ids) $ \ batch -> do
676+ for_ batch $ \ (_, (ident, reason)) -> logReason ident reason
677+ unregisterGhcPkgIds wc localDB $ map fst batch
678+ ACGhc v | v >= mkVersion [7 , 9 ] ->
679+ for_ ids $ \ (gid, (ident, reason)) -> do
680+ logReason ident reason
681+ unregisterGhcPkgIds wc localDB [gid]
682+ _ -> do
683+ for_ ids $ \ (_gid, (ident, reason)) -> do
684+ logReason ident reason
685+ unregisterSinglePackageId wc localDB ident
686+
664687toActions :: HasEnvConfig env
665688 => InstalledMap
666689 -> Maybe (MVar () )
0 commit comments