aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-17 14:52:10 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-17 14:52:10 +0200
commit0be5453f8bb50dd491bedd856d9625c5b5585148 (patch)
tree8cacf50e61131180e51065065a13b7e1334429b7 /app
parent8c374417d9ca0ee4c4d75ee171d8b4e2f150bf78 (diff)
refactor `cached`
Diffstat (limited to 'app')
-rw-r--r--app/History.hs24
1 files changed, 12 insertions, 12 deletions
diff --git a/app/History.hs b/app/History.hs
index 36dc1fc..7ed09bc 100644
--- a/app/History.hs
+++ b/app/History.hs
@@ -348,21 +348,21 @@ fixTreeGrepper treeGrepperResult =
cached :: Binary a => Text -> (Text -> IO a) -> IO a
cached hash func = do
+ -- FIXME Cache inside Git root
+ --
+ -- The cache location should not be dependant on the current directory, but
+ -- should be placed alongside the `.git` directory.
cwd <- getCurrentDirectory
createDirectoryIfMissing True (cwd ++ "/.anissue")
let file = (cwd ++ "/.anissue/" ++ unpack hash)
- fileExists <- doesFileExist file
- if fileExists
- then do
- result <- decodeFileOrFail file
- case result of
- Left _ -> do
- blob <- func hash
- encodeFile file blob
- pure blob
- Right blob ->
- pure blob
- else do
+ doesFileExist file >>= \case
+ True ->
+ decodeFileOrFail file >>= \case
+ Left _ -> generate file
+ Right blob -> pure blob
+ False -> generate file
+ where
+ generate file = do
blob <- func hash
encodeFile file blob
pure blob