From 4295de01bc524b5dccb17dfe2e50f2121feeea07 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sun, 24 Jan 2010 11:31:36 +0100 Subject: Added tagMap caching. Because the readTagMap function was currently one of the bottlenexks, this has caused a speedup of 900% for some test cases, so yay for that. --- src/Text/Hakyll/Tags.hs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/Text/Hakyll/Tags.hs') diff --git a/src/Text/Hakyll/Tags.hs b/src/Text/Hakyll/Tags.hs index a2031f8..6a179a5 100644 --- a/src/Text/Hakyll/Tags.hs +++ b/src/Text/Hakyll/Tags.hs @@ -24,6 +24,8 @@ import qualified Data.Map as M import Data.List (intercalate) import Control.Monad (foldM) import Control.Arrow (second) +import Control.Applicative ((<$>)) +import System.FilePath (()) import Text.Hakyll.Hakyll (Hakyll) import Text.Hakyll.Context (ContextManipulation, changeValue) @@ -31,11 +33,26 @@ import Text.Hakyll.Render.Internal (finalSubstitute) import Text.Hakyll.Regex import Text.Hakyll.Util import Text.Hakyll.Page +import Text.Hakyll.Internal.Cache -- | Read a tag map. This creates a map from tags to page paths. -readTagMap :: [FilePath] -> Hakyll (M.Map String [FilePath]) -readTagMap paths = foldM addPaths M.empty paths +-- +-- You also have to give a unique identifier for every tagmap. This is for +-- caching reasons, so the tagmap will be stored in +-- @_cache/_tagmap/identifier@. +readTagMap :: String -- ^ Unique identifier for the tagmap. + -> [FilePath] + -> Hakyll (M.Map String [FilePath]) +readTagMap identifier paths = do + isCacheMoreRecent' <- isCacheMoreRecent fileName paths + if isCacheMoreRecent' then M.fromList <$> getFromCache fileName + else do tagMap <- readTagMap' + storeInCache (M.toList tagMap) fileName + return tagMap where + fileName = "_tagmap" identifier + + readTagMap' = foldM addPaths M.empty paths addPaths current path = do page <- readPage path let tags = map trim $ splitRegex "," $ getValue "tags" page -- cgit v1.2.3