From 2e3bb0e67c4c255d07f866c827b741042668f842 Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Wed, 18 May 2016 06:40:32 -0400 Subject: [PATCH] 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. --- app/Main.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Main.hs b/app/Main.hs index 96ae6c5..9361993 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -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"