add cache for getNumMinCopiesAttr
authorJoey Hess <joeyh@joeyh.name>
Mon, 12 May 2025 18:37:23 +0000 (14:37 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 12 May 2025 18:37:23 +0000 (14:37 -0400)
Optimises balanced=groupname:lackingcopies at the expense of a tiny
slowdown to lackingcopies=number and git-annex fsck and import.

Sponsored-by: k0ld
Annex.hs
Annex/NumCopies.hs

index 582ffd644dda3a2b277346061c797b0ad8292408..84b2bda0ad11710a384312e4e30274920cb9cac8 100644 (file)
--- a/Annex.hs
+++ b/Annex.hs
@@ -197,6 +197,7 @@ data AnnexState = AnnexState
        , checkignorehandle :: Maybe (ResourcePool CheckIgnoreHandle)
        , globalnumcopies :: Maybe (Maybe NumCopies)
        , globalmincopies :: Maybe (Maybe MinCopies)
+       , nummincopiesattrcache :: Maybe (OsPath, (Maybe NumCopies, Maybe MinCopies))
        , limit :: ExpandableMatcher Annex
        , timelimit :: Maybe (Duration, POSIXTime)
        , sizelimit :: Maybe (TVar Integer)
@@ -253,6 +254,7 @@ newAnnexState c r = do
                , checkignorehandle = Nothing
                , globalnumcopies = Nothing
                , globalmincopies = Nothing
+               , nummincopiesattrcache = Nothing
                , limit = BuildingMatcher []
                , timelimit = Nothing
                , sizelimit = Nothing
index a3885415c58304859072c260ac9fa3634b9700ef..83a957cec9319f123d260589516af48e09a4ae38 100644 (file)
@@ -1,6 +1,6 @@
 {- git-annex numcopies configuration and checking
  -
- - Copyright 2014-2024 Joey Hess <id@joeyh.name>
+ - Copyright 2014-2025 Joey Hess <id@joeyh.name>
  -
  - Licensed under the GNU AGPL version 3 or higher.
  -}
@@ -181,12 +181,18 @@ getGlobalFileNumCopies f = fromSourcesOr defaultNumCopies
        ]
 
 getNumMinCopiesAttr :: OsPath  -> Annex (Maybe NumCopies, Maybe MinCopies)
-getNumMinCopiesAttr file =
-       checkAttrs ["annex.numcopies", "annex.mincopies"] file >>= \case
-               (n:m:[]) -> return
-                       ( configuredNumCopies <$> readish n
-                       , configuredMinCopies <$> readish m
-                       )
+getNumMinCopiesAttr file = Annex.getState Annex.nummincopiesattrcache >>= \case
+       Just (cfile, v) | cfile == file -> return v
+       _ -> checkAttrs ["annex.numcopies", "annex.mincopies"] file >>= \case
+               (n:m:[]) -> do
+                       let v =
+                               ( configuredNumCopies <$> readish n
+                               , configuredMinCopies <$> readish m
+                               )
+                       Annex.changeState $ \s -> s 
+                               { Annex.nummincopiesattrcache = Just (file, v)
+                               }
+                       return v
                _ -> error "internal"
 
 {- Checks if numcopies are satisfied for a file by running a comparison