optimisation for borg

Skip needing to list importable contents when unchanged since last time.
This commit is contained in:
Joey Hess 2020-12-22 14:35:02 -04:00
parent e1ac42be77
commit 4f9969d0a1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
9 changed files with 32 additions and 21 deletions

View file

@ -26,6 +26,7 @@ import Utility.Metered
import qualified Remote.Helper.ThirdPartyPopulated as ThirdPartyPopulated
import Logs.Export
import Data.Either
import Text.Read
import Control.Exception (evaluate)
import Control.DeepSeq
@ -122,8 +123,6 @@ borgSetup _ mu _ c _gc = do
-- persistant state, so it can vary between hosts.
gitConfigSpecialRemote u c [("borgrepo", borgrepo)]
-- TODO: untrusted by default, but allow overriding that
return (c, u)
borgLocal :: BorgRepo -> Bool
@ -132,18 +131,20 @@ borgLocal = notElem ':'
-- XXX the tree generated by using this does not seem to get grafted into
-- the git-annex branch, so would be subject to being lost to GC.
-- Is this a general problem affecting importtree too?
listImportableContentsM :: UUID -> BorgRepo -> Annex (ImportableContents (ContentIdentifier, ByteSize))
listImportableContentsM :: UUID -> BorgRepo -> Annex (Maybe (ImportableContents (ContentIdentifier, ByteSize)))
listImportableContentsM u borgrepo = prompt $ do
imported <- getImported u
ls <- withborglist borgrepo "{barchive}{NUL}" $ \as ->
forM as $ \archivename ->
case M.lookup archivename imported of
Just getfast -> getfast
Nothing ->
Just getfast -> return $ Left getfast
Nothing -> Right <$>
let archive = borgrepo ++ "::" ++ decodeBS' archivename
in withborglist archive "{size}{NUL}{path}{NUL}" $
liftIO . evaluate . force . parsefilelist archivename
return $ mkimportablecontents ls
if all isLeft ls
then return Nothing -- unchanged since last time, avoid work
else Just . mkimportablecontents <$> mapM (either id pure) ls
where
withborglist what format a = do
let p = (proc "borg" ["list", what, "--format", format])