From 7c3f0eae77b07ccc65c4e30d9eb1288781bd0c02 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 21 Jan 2014 18:46:39 -0400 Subject: benchmarked numcopies .gitattributes in preferred content Checking .gitattributes adds a full minute to a git annex find looking for files that don't have enough copies. 2:25 increasts to 3:27. I feel this is too much of a slowdown to justify making it the default. So, exposed two versions of the preferred content expression, a slow one and a fast but approximate one. I'm using the approximate one in the default preferred content expressions to avoid slowing down the assistant. --- Limit.hs | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'Limit.hs') diff --git a/Limit.hs b/Limit.hs index 471a0c278..6ce444325 100644 --- a/Limit.hs +++ b/Limit.hs @@ -178,29 +178,26 @@ limitCopies want = case split ":" want of | "+" `isSuffixOf` s = (>=) <$> readTrustLevel (beginning s) | otherwise = (==) <$> readTrustLevel s -{- Adds a limit to match files that need more copies made. - - - - Does not look at annex.numcopies .gitattributes, because that - - would require querying git check-attr every time a preferred content - - expression is checked, which would probably be quite slow. - -} -addNumCopiesNeeded :: String -> Annex () -addNumCopiesNeeded = addLimit . limitNumCopiesNeeded - -limitNumCopiesNeeded :: MkLimit -limitNumCopiesNeeded want = case readish want of - Just needed -> Right $ \notpresent -> checkKey $ - handle needed notpresent - Nothing -> Left "bad value for numcopiesneeded" +{- Adds a limit to match files that need more copies made. -} +addLackingCopies :: Bool -> String -> Annex () +addLackingCopies approx = addLimit . limitLackingCopies approx + +limitLackingCopies :: Bool -> MkLimit +limitLackingCopies approx want = case readish want of + Just needed -> Right $ \notpresent mi -> flip checkKey mi $ + handle mi needed notpresent + Nothing -> Left "bad value for number of lacking copies" where - handle needed notpresent key = do - gv <- getGlobalNumCopies - case gv of - Nothing -> return False - Just (NumCopies numcopies) -> do - us <- filter (`S.notMember` notpresent) - <$> (trustExclude UnTrusted =<< Remote.keyLocations key) - return $ numcopies - length us >= needed + handle mi needed notpresent key = do + NumCopies numcopies <- if approx + then approxNumCopies + else case mi of + MatchingKey _ -> approxNumCopies + MatchingFile fi -> getGlobalFileNumCopies $ matchFile fi + us <- filter (`S.notMember` notpresent) + <$> (trustExclude UnTrusted =<< Remote.keyLocations key) + return $ numcopies - length us >= needed + approxNumCopies = fromMaybe defaultNumCopies <$> getGlobalNumCopies {- Adds a limit to skip files not believed to be present in all - repositories in the specified group. -} -- cgit v1.2.3