Users opt into using the cache

Why?
====

Calculating the SHA of the entire tree can be expensive; this shifts
reading from/writing to the cache to be configured via a switch in the
CLI.

In the future, it might make sense to store metadata about the repo,
including historical time to calculate both the SHA and non-cached
versions, to compare and choose which one to do intelligently.
This commit is contained in:
Joshua Clayton 2016-05-18 06:40:32 -04:00
parent c77cd2a8f6
commit 2e3bb0e67c

View File

@ -17,6 +17,7 @@ data Options = Options
, oAllLikelihoods :: Bool
, oIgnoredPaths :: [String]
, oGrouping :: CurrentGrouping
, oWithCache :: Bool
}
main :: IO ()
@ -38,7 +39,7 @@ run options = withoutCursor $ do
terms <- pure . lines =<< getContents
renderHeader terms
results <- cached $ unlines <$> executeSearch (oSearchRunner options) terms
results <- withCache options $ unlines <$> executeSearch (oSearchRunner options) terms
let response = parseLines results
resetScreen
@ -48,6 +49,10 @@ run options = withoutCursor $ do
return ()
withCache :: Options -> IO String -> IO String
withCache Options{ oWithCache = True } = cached
withCache Options{ oWithCache = False } = id
withInfo :: Parser a -> String -> String -> String -> ParserInfo a
withInfo opts h d f =
info (helper <*> opts) $ header h <> progDesc d <> footer f
@ -75,6 +80,7 @@ parseOptions =
<*> parseAllLikelihoods
<*> parseIgnorePaths
<*> parseGroupings
<*> parseWithCache
parseSearchRunner :: Parser SearchRunner
parseSearchRunner =
@ -134,3 +140,9 @@ parseGroupingOption = strOption $
short 'g'
<> long "group-by"
<> help "[Allowed: directory, term, file, none] Group results"
parseWithCache :: Parser Bool
parseWithCache = switch $
short 'c'
<> long "with-cache"
<> help "Write to cache and read when available"