avoid reposize database locking overhead when not needed

Only when the preferred content expression being matched uses balanced
preferred content is this overhead needed.

It might be possible to eliminate the locking entirely. Eg, check the
live changes before and after the action and re-run if they are not
stable. For now, this is good enough, it avoids existing preferred
content getting slow. If balanced preferred content turns out to be too
slow to check, that could be tried later.
This commit is contained in:
Joey Hess 2024-08-28 10:52:34 -04:00
parent 09955deebe
commit e006acef22
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 43 additions and 12 deletions

View file

@ -90,7 +90,7 @@ checkMatcher matcher mkey afile lu notpresent notconfigured d
checkMatcher' :: FileMatcher Annex -> MatchInfo -> LiveUpdate -> AssumeNotPresent -> Annex Bool
checkMatcher' (matcher, (MatcherDesc matcherdesc)) mi lu notpresent =
checkLiveUpdate lu go
checkLiveUpdate lu matcher go
where
go = do
(matches, desc) <- runWriterT $ matchMrun' matcher $ \op ->
@ -281,6 +281,7 @@ call desc (Right sub) = Right $ Operation $ MatchFiles
, matchNeedsFileContent = any matchNeedsFileContent sub
, matchNeedsKey = any matchNeedsKey sub
, matchNeedsLocationLog = any matchNeedsLocationLog sub
, matchNeedsLiveRepoSize = any matchNeedsLiveRepoSize sub
, matchDesc = matchDescSimple desc
}
call _ (Left err) = Left err

View file

@ -13,6 +13,8 @@ import Annex.Common
import Logs.Presence.Pure
import qualified Database.RepoSize as Db
import Annex.UUID
import Types.FileMatcher
import qualified Utility.Matcher as Matcher
import Control.Concurrent
import System.Process
@ -95,9 +97,16 @@ needLiveUpdate lu = liftIO $ void $ tryPutMVar (liveUpdateNeeded lu) ()
-- This serializes calls to the action, so that if the action
-- queries getLiveRepoSizes it will not race with another such action
-- that may also be starting a live update.
checkLiveUpdate :: LiveUpdate -> Annex Bool -> Annex Bool
checkLiveUpdate NoLiveUpdate a = a
checkLiveUpdate lu a = Db.lockDbWhile (const go) go
checkLiveUpdate
:: LiveUpdate
-> Matcher.Matcher (MatchFiles Annex)
-> Annex Bool
-> Annex Bool
checkLiveUpdate NoLiveUpdate _ a = a
checkLiveUpdate lu matcher a
| Matcher.introspect matchNeedsLiveRepoSize matcher =
Db.lockDbWhile (const go) go
| otherwise = a
where
go = do
r <- a