avoid reloading trust log
authorJoey Hess <joeyh@joeyh.name>
Wed, 19 Mar 2025 13:35:29 +0000 (09:35 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 19 Mar 2025 13:44:44 +0000 (09:44 -0400)
Logs/Trust.hs
Logs/Trust/Basic.hs
Remote/Compute.hs

index f7a705f7ded75aeecbee8bc77679cfa5fafd0773..4554145a0d9405d6a807e4c31a0ce3e57a134610 100644 (file)
@@ -20,7 +20,6 @@ module Logs.Trust (
 
 import Annex.Common
 import Types.TrustLevel
-import qualified Annex
 import Logs
 import Remote.List
 import Logs.Trust.Basic as X
@@ -61,7 +60,7 @@ trustExclude level ls = snd <$> trustPartition level ls
 {- trustLog in a map, overridden with any values from forcetrust or
  - the git config. The map is cached for speed. -}
 trustMap :: Annex TrustMap
-trustMap = maybe trustMapLoad return =<< Annex.getState Annex.trustmap
+trustMap = trustMap' =<< remoteList
 
 {- Loads the map, updating the cache, -}
 trustMapLoad :: Annex TrustMap
index b05c072927a948f68cbab66ea90205029001eeeb..8697df635ba935ddf632038a4f48d8dee4b64c23 100644 (file)
@@ -9,6 +9,7 @@ module Logs.Trust.Basic (
        module X,
        trustSet,
        trustMapRaw,
+       trustMap',
        trustMapLoad',
 ) where
 
@@ -39,6 +40,9 @@ trustSet NoUUID _ = error "unknown UUID; cannot modify"
 trustMapRaw :: Annex TrustMap
 trustMapRaw = calcTrustMap <$> Annex.Branch.get trustLog
 
+trustMap' :: [Remote] -> Annex TrustMap
+trustMap' l = maybe (trustMapLoad' l) return =<< Annex.getState Annex.trustmap
+
 trustMapLoad' :: [Remote] -> Annex TrustMap
 trustMapLoad' l = do
        forceoverrides <- Annex.getState Annex.forcetrust
index 792105a1b89b2a1e51f9cbf37077ab20fc7fb387..140eb9bd943fa43e15a3f298487acdf0b36a850f 100644 (file)
@@ -755,6 +755,8 @@ computeKey rs (ComputeProgram program) k _af dest meterupdate vc =
                
 keyPossibilities :: Key -> Annex [Remote]
 keyPossibilities key = do
+       -- This gets populated with a list of all remotes before this
+       -- remote is used.
        remotelist <- Annex.getState Annex.remotes
        locs <- loggedLocations key
        keyPossibilities' (IncludeIgnored False) key locs remotelist
@@ -804,12 +806,23 @@ avoidCycles outputkeys inputkey = filterM go
 -- its inputs are also still available.
 checkKey :: RemoteStateHandle -> Key -> Annex Bool
 checkKey rs k = do
-       deadset <- S.fromList . M.keys . M.filter (== DeadTrusted)
-               <$> (trustMapLoad' =<< Annex.getState Annex.remotes)
-       computeset <- S.fromList . M.keys . M.filter isComputeRemote'
-               <$> remoteConfigMap
+       deadset <- getdeadset
+       computeset <- getcomputeset
        availablecompute [] deadset computeset k rs
   where
+       getdeadset = do
+               -- Usually this will already be populated with all remotes,
+               -- otherwise this compute remote would not be used. Check
+               -- just in case, to avoid trustMap' caching bad inputs.
+               rs <- Annex.getState Annex.remotes
+               if null rs
+                       then error "internal"
+                       else S.fromList . M.keys . M.filter (== DeadTrusted)
+                               <$> trustMap' rs
+
+       getcomputeset = S.fromList . M.keys . M.filter isComputeRemote'
+               <$> remoteConfigMap
+
        availablecompute inputkeys deadset computeset k' rs'
                | k' `elem` inputkeys = return False -- avoid cycles
                | otherwise =