@@ -172,9 +172,9 @@ getRegistryFns registryBox registryLock = do
172172 -- we keep track of how old the latest pull was - if the last pull was recent enough
173173 -- we just move on, otherwise run the fibers
174174 { db, offline } <- ask
175- fetchingFreshRegistry <- shouldFetchRegistryRepos db
175+ fetchingFreshRegistry <- shouldFetchRegistryRepos offline db
176176 -- we also check if we need to bypass this cache (for when we need the freshest data)
177- when (fetchingFreshRegistry || offline == OnlineBypassCache ) do
177+ when (fetchingFreshRegistry || offline == OnlineBypassCache || offline == OnlineRefreshRegistry ) do
178178 -- clone the registry and index repo, or update them
179179 logInfo " Refreshing the Registry Index..."
180180 parallelise
@@ -264,7 +264,7 @@ getMetadataImpl db onlineStatus name =
264264-- Parallelised version of `getMetadataImpl`
265265getMetadataForPackagesImpl :: Db -> OnlineStatus -> Array PackageName -> Spago (LogEnv ()) (Either String (Map PackageName Metadata ))
266266getMetadataForPackagesImpl db onlineStatus names = do
267- (map Map .fromFoldable <<< sequence) <$> case onlineStatus == OnlineBypassCache of
267+ (map Map .fromFoldable <<< sequence) <$> case onlineStatus == OnlineBypassCache || onlineStatus == OnlineRefreshRegistry of
268268 true -> do
269269 logDebug " Bypassing cache, reading metadata from file"
270270 parTraverseSpago metadataFromFile names
@@ -367,31 +367,37 @@ isVersionCompatible installedVersion minVersion =
367367 [ a, b, _c ], [ x, y, _z ] | a /= 0 && a == x && b >= y -> true
368368 _, _ -> false
369369
370- -- | Check if we have fetched the registry recently enough, so we don't hit the net all the time
371- shouldFetchRegistryRepos :: ∀ a . Db -> Spago (LogEnv a ) Boolean
372- shouldFetchRegistryRepos db = do
370+ -- | Check if we have fetched the registry recently enough, so we don't hit the net all the time.
371+ -- | When `OnlineRefreshRegistry` is set, always fetch regardless of staleness.
372+ shouldFetchRegistryRepos :: ∀ a . OnlineStatus -> Db -> Spago (LogEnv a ) Boolean
373+ shouldFetchRegistryRepos offline db = do
373374 now <- liftEffect $ Now .nowDateTime
374375 let registryKey = " registry"
375- maybeLastRegistryFetch <- liftEffect $ Db .getLastPull db registryKey
376- case maybeLastRegistryFetch of
377- -- No record, so we have to fetch
378- Nothing -> do
379- logDebug " No record of last registry pull, will fetch"
380- liftEffect $ Db .updateLastPull db registryKey now
381- pure true
382- -- We have a record, so we check if it's old enough
383- Just lastRegistryFetch -> do
384- let staleAfter = Minutes 15.0
385- let (timeDiff :: Minutes ) = DateTime .diff now lastRegistryFetch
386- let isOldEnough = timeDiff > staleAfter
387- -- We check if it's old, but also if we have it at all
388- registryExists <- FS .exists Paths .registryPath
389- if isOldEnough || not registryExists then do
390- logDebug " Registry is old, refreshing"
376+ if offline == OnlineRefreshRegistry then do
377+ logDebug " Refresh flag set, will fetch registry"
378+ liftEffect $ Db .updateLastPull db registryKey now
379+ pure true
380+ else do
381+ maybeLastRegistryFetch <- liftEffect $ Db .getLastPull db registryKey
382+ case maybeLastRegistryFetch of
383+ -- No record, so we have to fetch
384+ Nothing -> do
385+ logDebug " No record of last registry pull, will fetch"
391386 liftEffect $ Db .updateLastPull db registryKey now
392387 pure true
393- else do
394- pure false
388+ -- We have a record, so we check if it's old enough
389+ Just lastRegistryFetch -> do
390+ let staleAfter = Minutes 15.0
391+ let (timeDiff :: Minutes ) = DateTime .diff now lastRegistryFetch
392+ let isOldEnough = timeDiff > staleAfter
393+ -- We check if it's old, but also if we have it at all
394+ registryExists <- FS .exists Paths .registryPath
395+ if isOldEnough || not registryExists then do
396+ logDebug " Registry is old, refreshing"
397+ liftEffect $ Db .updateLastPull db registryKey now
398+ pure true
399+ else do
400+ pure false
395401
396402-- ------------------------------------------------------------------------------
397403-- | Registry operations
0 commit comments