diff options
-rw-r--r-- | src/Hakyll/Core/Provider/MetadataCache.hs | 8 | ||||
-rw-r--r-- | src/Hakyll/Core/Store.hs | 16 | ||||
-rw-r--r-- | tests/Hakyll/Core/Store/Tests.hs | 9 |
3 files changed, 14 insertions, 19 deletions
diff --git a/src/Hakyll/Core/Provider/MetadataCache.hs b/src/Hakyll/Core/Provider/MetadataCache.hs index 031960c..28d2bd5 100644 --- a/src/Hakyll/Core/Provider/MetadataCache.hs +++ b/src/Hakyll/Core/Provider/MetadataCache.hs @@ -7,8 +7,8 @@ module Hakyll.Core.Provider.MetadataCache -------------------------------------------------------------------------------- +import Control.Monad (unless) import qualified Data.Map as M -import Control.Monad (unless) -------------------------------------------------------------------------------- import Hakyll.Core.Identifier @@ -51,9 +51,9 @@ load :: Provider -> Identifier -> IO () load p r = do mmof <- Store.isMember store mdk unless mmof $ do - (md, body) <- loadMetadata p r - Store.set store mdk md - Store.set store bk body + (md, body) <- loadMetadata p r + Store.set store mdk md + Store.set store bk body where store = providerStore p mdk = [name, toFilePath r, "metadata"] diff --git a/src/Hakyll/Core/Store.hs b/src/Hakyll/Core/Store.hs index b2c61a0..74d9d2f 100644 --- a/src/Hakyll/Core/Store.hs +++ b/src/Hakyll/Core/Store.hs @@ -24,6 +24,7 @@ import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import qualified Data.Cache.LRU.IO as Lru import Data.List (intercalate) +import Data.Maybe (isJust) import qualified Data.Text as T import qualified Data.Text.Encoding as T import Data.Typeable (TypeRep, Typeable, cast, typeOf) @@ -103,12 +104,8 @@ cacheLookup (Store _ (Just lru)) key = do -------------------------------------------------------------------------------- cacheIsMember :: Store -> String -> IO Bool -cacheIsMember (Store _ Nothing) _ = return False -cacheIsMember (Store _ (Just lru)) key = do - res <- Lru.lookup key lru - case res of - Nothing -> return False - _ -> return True +cacheIsMember (Store _ Nothing) _ = return False +cacheIsMember (Store _ (Just lru)) key = isJust <$> Lru.lookup key lru -------------------------------------------------------------------------------- @@ -168,9 +165,10 @@ isMember :: Store -> [String] -> IO Bool isMember store identifier = do inCache <- cacheIsMember store key if inCache then return True else doesFileExist path - where - key = hash identifier - path = storeDirectory store </> key + where + key = hash identifier + path = storeDirectory store </> key + -------------------------------------------------------------------------------- -- | Delete an item diff --git a/tests/Hakyll/Core/Store/Tests.hs b/tests/Hakyll/Core/Store/Tests.hs index 389d7fd..0aa1aa4 100644 --- a/tests/Hakyll/Core/Store/Tests.hs +++ b/tests/Hakyll/Core/Store/Tests.hs @@ -72,15 +72,12 @@ wrongType = do -------------------------------------------------------------------------------- - isMembertest :: H.Assertion isMembertest = do store <- newTestStore Store.set store ["foo", "bar"] ("qux" :: String) - --value <- Store.get store ["foo", "bar"] :: IO (Store.Result Int) good <- Store.isMember store ["foo", "bar"] - - bad <- Store.isMember store ["foo", "baz"] - H.assert good + bad <- Store.isMember store ["foo", "baz"] + H.assert good H.assert (not bad) - cleanTestEnv
\ No newline at end of file + cleanTestEnv |