update ExportTree table efficiently

Use same diff and key lookup except when the whole tree has to be
scanned.

This commit was sponsored by Peter Hogg on Patreon.
This commit is contained in:
Joey Hess 2017-09-18 14:24:42 -04:00
parent b03d77c211
commit 0ad7e36dc1
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 29 additions and 19 deletions

View file

@ -22,7 +22,10 @@ module Database.Export (
getExportedLocation,
isExportDirectoryEmpty,
getExportTree,
addExportTree,
removeExportTree,
updateExportTree,
updateExportTree',
ExportedId,
ExportTreeId,
ExportedDirectoryId,
@ -183,18 +186,22 @@ updateExportTree h old new = do
(diff, cleanup) <- inRepo $
Git.DiffTree.diffTreeRecursive old new
forM_ diff $ \i -> do
let loc = mkExportLocation $ getTopFilePath $
Git.DiffTree.file i
srcek <- getek (Git.DiffTree.srcsha i)
case srcek of
Nothing -> return ()
Just k -> liftIO $ removeExportTree h (asKey k) loc
dstek <- getek (Git.DiffTree.dstsha i)
case dstek of
Nothing -> return ()
Just k -> liftIO $ addExportTree h (asKey k) loc
updateExportTree' h srcek dstek i
void $ liftIO cleanup
where
getek sha
| sha == nullSha = return Nothing
| otherwise = Just <$> exportKey sha
updateExportTree' :: ExportHandle -> Maybe ExportKey -> Maybe ExportKey -> Git.DiffTree.DiffTreeItem-> Annex ()
updateExportTree' h srcek dstek i = do
case srcek of
Nothing -> return ()
Just k -> liftIO $ removeExportTree h (asKey k) loc
case dstek of
Nothing -> return ()
Just k -> liftIO $ addExportTree h (asKey k) loc
where
loc = mkExportLocation $ getTopFilePath $ Git.DiffTree.file i