summaryrefslogtreecommitdiffstats
path: root/app/Document.hs
diff options
context:
space:
mode:
Diffstat (limited to 'app/Document.hs')
-rw-r--r--app/Document.hs22
1 files changed, 15 insertions, 7 deletions
diff --git a/app/Document.hs b/app/Document.hs
index ac8a73b..fa9f33f 100644
--- a/app/Document.hs
+++ b/app/Document.hs
@@ -1,6 +1,7 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
module Document
@@ -15,7 +16,7 @@ module Document
)
where
-import Control.Concurrent.ParallelIO.Local (parallel, withPool)
+import Control.DeepSeq (NFData (rnf))
import Control.Exception (Exception, throwIO)
import Data.Aeson qualified as J
import Data.ByteString.Lazy qualified as LB
@@ -26,9 +27,9 @@ import Data.Set qualified as S
import Data.Text qualified as T
import Data.Time.Clock (UTCTime)
import Data.Time.Format.ISO8601 (iso8601Show)
-import GHC.Conc (getNumProcessors)
import GHC.Generics (Generic)
import GHC.Records (HasField (..))
+import Parallel (parMapM)
import System.Directory (listDirectory)
import System.FilePath (takeBaseName, (<.>), (</>))
import Tag qualified as G
@@ -42,6 +43,9 @@ data Document = Document
}
deriving (Show)
+instance NFData Document where
+ rnf (Document {..}) = rnf iFileName `seq` rnf index
+
instance HasField "oFilePath" Document FilePath where
getField doc = "originals" </> takeBaseName doc.iFileName <.> "pdf"
@@ -86,6 +90,15 @@ data Index = Index
}
deriving (Show, Generic, Eq)
+instance NFData Index where
+ rnf (Index {..}) =
+ rnf content `seq`
+ rnf tags `seq`
+ rnf addedAt `seq`
+ rnf modifiedAt `seq`
+ rnf todo `seq`
+ rnf language
+
instance J.ToJSON Index
instance J.FromJSON Index
@@ -118,11 +131,6 @@ internalTags index =
]
)
-parMapM :: (a -> IO b) -> [a] -> IO [b]
-parMapM f xs = do
- n <- getNumProcessors
- withPool n $ \pool -> parallel pool (map f xs)
-
data DecodeException = DecodeException FilePath String
deriving (Show)