cache remote.log

Unlikely to speed up any of the existing uses much, but I want to use it
in a message that might be displayed many times.
This commit is contained in:
Joey Hess 2020-09-22 13:52:26 -04:00
parent ebdce707da
commit 5cfcf1f05f
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
19 changed files with 62 additions and 29 deletions

View file

@ -1,12 +1,13 @@
{- git-annex remote log
-
- Copyright 2011-2019 Joey Hess <id@joeyh.name>
- Copyright 2011-2020 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Logs.Remote (
remoteLog,
remoteConfigMap,
readRemoteLog,
configSet,
keyValToConfig,
@ -18,6 +19,7 @@ module Logs.Remote (
) where
import Annex.Common
import qualified Annex
import qualified Annex.Branch
import Types.Remote
import Logs
@ -35,8 +37,20 @@ configSet u cfg = do
buildRemoteConfigLog
. changeLog c u (removeSameasInherited cfg)
. parseRemoteConfigLog
Annex.changeState $ \s -> s { Annex.remoteconfigmap = Nothing }
{- Map of remotes by uuid containing key/value config maps.
- Cached for speed. -}
remoteConfigMap :: Annex (M.Map UUID RemoteConfig)
remoteConfigMap = maybe remoteConfigMapLoad return
=<< Annex.getState Annex.remoteconfigmap
remoteConfigMapLoad :: Annex (M.Map UUID RemoteConfig)
remoteConfigMapLoad = do
m <- readRemoteLog
Annex.changeState $ \s -> s { Annex.remoteconfigmap = Just m }
return m
{- Map of remotes by uuid containing key/value config maps. -}
readRemoteLog :: Annex (M.Map UUID RemoteConfig)
readRemoteLog = calcRemoteConfigMap
<$> Annex.Branch.get remoteLog