Check modification only once

This commit is contained in:
Jasper Van der Jeugt 2010-12-31 15:15:35 +01:00
parent 8bb4ea5c83
commit e54834f444
3 changed files with 25 additions and 9 deletions

View file

@ -83,10 +83,9 @@ cached :: (Binary a)
-> Compiler () a -> Compiler () a
-> Compiler () a -> Compiler () a
cached name (Compiler d j) = Compiler d $ const $ CompilerM $ do cached name (Compiler d j) = Compiler d $ const $ CompilerM $ do
provider <- compilerResourceProvider <$> ask
identifier <- compilerIdentifier <$> ask identifier <- compilerIdentifier <$> ask
store <- compilerStore <$> ask store <- compilerStore <$> ask
modified <- liftIO $ resourceModified provider identifier store modified <- compilerResourceModified <$> ask
liftIO $ putStrLn $ liftIO $ putStrLn $
show identifier ++ ": " ++ if modified then "MODIFIED" else "OK" show identifier ++ ": " ++ if modified then "MODIFIED" else "OK"
if modified if modified

View file

@ -37,11 +37,18 @@ type DependencyLookup = Identifier -> CompiledItem
-- | Environment in which a compiler runs -- | Environment in which a compiler runs
-- --
data CompilerEnvironment = CompilerEnvironment data CompilerEnvironment = CompilerEnvironment
{ compilerIdentifier :: Identifier -- ^ Target identifier { -- | Target identifier
, compilerResourceProvider :: ResourceProvider -- ^ Resource provider compilerIdentifier :: Identifier
, compilerDependencyLookup :: DependencyLookup -- ^ Dependency lookup , -- | Resource provider
, compilerRoute :: Maybe FilePath -- ^ Site route compilerResourceProvider :: ResourceProvider
, compilerStore :: Store -- ^ Compiler store , -- | Dependency lookup
compilerDependencyLookup :: DependencyLookup
, -- | Site route
compilerRoute :: Maybe FilePath
, -- | Compiler store
compilerStore :: Store
, -- | Flag indicating if the underlying resource was modified
compilerResourceModified :: Bool
} }
-- | The compiler monad -- | The compiler monad
@ -76,8 +83,9 @@ runCompilerJob :: Compiler () a -- ^ Compiler to run
-> DependencyLookup -- ^ Dependency lookup table -> DependencyLookup -- ^ Dependency lookup table
-> Maybe FilePath -- ^ Route -> Maybe FilePath -- ^ Route
-> Store -- ^ Store -> Store -- ^ Store
-> Bool -- ^ Was the resource modified?
-> IO a -> IO a
runCompilerJob compiler identifier provider lookup' route store = runCompilerJob compiler identifier provider lookup' route store modified =
runReaderT (unCompilerM $ compilerJob compiler ()) env runReaderT (unCompilerM $ compilerJob compiler ()) env
where where
env = CompilerEnvironment env = CompilerEnvironment
@ -86,6 +94,7 @@ runCompilerJob compiler identifier provider lookup' route store =
, compilerDependencyLookup = lookup' , compilerDependencyLookup = lookup'
, compilerRoute = route , compilerRoute = route
, compilerStore = store , compilerStore = store
, compilerResourceModified = modified
} }
runCompilerDependencies :: Compiler () a runCompilerDependencies :: Compiler () a

View file

@ -67,8 +67,15 @@ hakyllWith rules provider store = do
where where
addTarget route' map' (id', comp) = do addTarget route' map' (id', comp) = do
let url = runRoute route' id' let url = runRoute route' id'
-- Check if the resource was modified
modified <- if resourceExists provider id'
then resourceModified provider id' store
else return False
-- Run the compiler
compiled <- runCompilerJob comp id' provider (dependencyLookup map') compiled <- runCompilerJob comp id' provider (dependencyLookup map')
url store url store modified
putStrLn $ "Generated target: " ++ show id' putStrLn $ "Generated target: " ++ show id'
case url of case url of
@ -79,6 +86,7 @@ hakyllWith rules provider store = do
makeDirectories path makeDirectories path
write path compiled write path compiled
putStrLn ""
return $ M.insert id' compiled map' return $ M.insert id' compiled map'
dependencyLookup map' id' = case M.lookup id' map' of dependencyLookup map' id' = case M.lookup id' map' of