summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-06-23 21:25:39 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-06-23 21:25:39 -0400
commit69d3c1cec9f6be1dba1ffb391bf69464c52f5936 (patch)
tree25409afd87286b599c65bd61e403a597413a86b0
parenta61154baf5e205af74766f44fe99cbbd63411f57 (diff)
cache the trustmap
Doubles the speed of fsck, and speeds up drop as well.
-rw-r--r--Annex.hs4
-rw-r--r--GitAnnex.hs2
-rw-r--r--Trust.hs19
-rw-r--r--Types/TrustLevel.hs (renamed from TrustLevel.hs)9
4 files changed, 24 insertions, 10 deletions
diff --git a/Annex.hs b/Annex.hs
index 2bd090e90..82908881d 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -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
}
diff --git a/GitAnnex.hs b/GitAnnex.hs
index 727e0c396..49ba63b8a 100644
--- a/GitAnnex.hs
+++ b/GitAnnex.hs
@@ -14,7 +14,7 @@ import CmdLine
import Command
import Options
import Utility
-import TrustLevel
+import Types.TrustLevel
import qualified Annex
import qualified Remote
diff --git a/Trust.hs b/Trust.hs
index d328235bf..365186da2 100644
--- a/Trust.hs
+++ b/Trust.hs
@@ -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
diff --git a/TrustLevel.hs b/Types/TrustLevel.hs
index 5da142ca3..058ce4595 100644
--- a/TrustLevel.hs
+++ b/Types/TrustLevel.hs
@@ -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