]> dgit.raspbian.org Git - git-annex.git/commitdiff
smarter BranchState cache invalidation
authorJoey Hess <joeyh@joeyh.name>
Sun, 28 Jul 2024 16:33:32 +0000 (12:33 -0400)
committerJoey Hess <joeyh@joeyh.name>
Sun, 28 Jul 2024 16:33:32 +0000 (12:33 -0400)
Only invalidate a just-written file in the cache, not the whole cache.

This will avoid the possibly performance impact of cache invalidation
mentioned in commit 770aac97a75f64b86d73240055acffe1a5ed9f1a

Annex/Branch.hs
Annex/BranchState.hs

index 806eabb99a31bd1711c0b4101733c8499918dc64..49225592b212143b57fbde6312826412c5500ffe 100644 (file)
@@ -262,7 +262,7 @@ updateTo' pairs = do
                                        else commitIndex jl branchref merge_desc commitrefs
                        )
                addMergedRefs tomerge
-               invalidateCache
+               invalidateCacheAll
        
        stagejournalwhen dirty jl a
                | dirty = stageJournal jl a
@@ -487,7 +487,7 @@ set jl ru f c = do
        -- evaluating a Journalable Builder twice, which is not very
        -- efficient. Instead, assume that it's not common to need to read
        -- a log file immediately after writing it.
-       invalidateCache
+       invalidateCache f
 
 {- Appends content to the journal file. -}
 append :: Journalable content => JournalLocked -> RawFilePath -> AppendableJournalFile -> content -> Annex ()
@@ -495,7 +495,7 @@ append jl f appendable toappend = do
        journalChanged
        appendJournalFile jl appendable toappend
        fastDebug "Annex.Branch" ("append " ++ fromRawFilePath f)
-       invalidateCache
+       invalidateCache f
 
 {- Commit message used when making a commit of whatever data has changed
  - to the git-annex branch. -}
index bfff7f61231ea17e5a2591b80732f0f7cbb991d3..0f0e55325935fbcafcc756a7c136c69d71beb427 100644 (file)
@@ -134,5 +134,11 @@ getCache file state = go (cachedFileContents state)
                | f == file && not (needInteractiveAccess state) = Just c
                | otherwise = go rest
 
-invalidateCache :: Annex ()
-invalidateCache = changeState $ \s -> s { cachedFileContents = [] }
+invalidateCache :: RawFilePath -> Annex ()
+invalidateCache f = changeState $ \s -> s
+       { cachedFileContents = filter (\(f', _) -> f' /= f) 
+               (cachedFileContents s)
+       }
+
+invalidateCacheAll :: Annex ()
+invalidateCacheAll = changeState $ \s -> s { cachedFileContents = [] }