cache the trustmap

Doubles the speed of fsck, and speeds up drop as well.
This commit is contained in:
Joey Hess 2011-06-23 21:25:39 -04:00
parent a61154baf5
commit 69d3c1cec9
4 changed files with 24 additions and 10 deletions

View file

@ -24,7 +24,7 @@ import Types.Backend
import Types.Remote
import Types.Crypto
import Types.BranchState
import TrustLevel
import Types.TrustLevel
import Types.UUID
-- git-annex's monad
@ -48,6 +48,7 @@ data AnnexState = AnnexState
, fromremote :: Maybe String
, exclude :: [String]
, forcetrust :: [(UUID, TrustLevel)]
, trustmap :: Maybe TrustMap
, cipher :: Maybe Cipher
}
@ -69,6 +70,7 @@ newState allbackends gitrepo = AnnexState
, fromremote = Nothing
, exclude = []
, forcetrust = []
, trustmap = Nothing
, cipher = Nothing
}

View file

@ -14,7 +14,7 @@ import CmdLine
import Command
import Options
import Utility
import TrustLevel
import Types.TrustLevel
import qualified Annex
import qualified Remote

View file

@ -9,15 +9,13 @@ module Trust (
TrustLevel(..),
trustLog,
trustGet,
trustMap,
trustMapParse,
trustSet
) where
import Control.Monad.State
import qualified Data.Map as M
import TrustLevel
import Types.TrustLevel
import qualified Branch
import Types
import UUID
@ -35,11 +33,17 @@ trustGet level = do
{- Read the trustLog into a map, overriding with any
- values from forcetrust -}
trustMap :: Annex (M.Map UUID TrustLevel)
trustMap :: Annex TrustMap
trustMap = do
overrides <- Annex.getState Annex.forcetrust
s <- Branch.get trustLog
return $ M.fromList $ trustMapParse s ++ overrides
cached <- Annex.getState Annex.trustmap
case cached of
Just m -> return m
Nothing -> do
overrides <- Annex.getState Annex.forcetrust
l <- Branch.get trustLog
let m = M.fromList $ trustMapParse l ++ overrides
Annex.changeState $ \s -> s { Annex.trustmap = Just m }
return m
{- Trust map parser. -}
trustMapParse :: String -> [(UUID, TrustLevel)]
@ -62,6 +66,7 @@ trustSet uuid level = do
when (M.lookup uuid m /= Just level) $ do
let m' = M.insert uuid level m
Branch.change trustLog (serialize m')
Annex.changeState $ \s -> s { Annex.trustmap = Just m' }
where
serialize m = unlines $ map showpair $ M.toList m
showpair (u, t) = u ++ " " ++ show t

View file

@ -5,10 +5,15 @@
- Licensed under the GNU GPL version 3 or higher.
-}
module TrustLevel (
module Types.TrustLevel (
TrustLevel(..),
TrustMap
) where
import qualified Data.Map as M
import Types.UUID
data TrustLevel = SemiTrusted | UnTrusted | Trusted
deriving Eq
@ -21,3 +26,5 @@ instance Read TrustLevel where
readsPrec _ "1" = [(Trusted, "")]
readsPrec _ "0" = [(UnTrusted, "")]
readsPrec _ _ = [(SemiTrusted, "")]
type TrustMap = M.Map UUID TrustLevel