diff options
| author | stuebinm | 2022-02-17 00:41:36 +0100 | 
|---|---|---|
| committer | stuebinm | 2022-03-19 19:29:16 +0100 | 
| commit | 53fb449b008e9b6aed9877b9d33f4026e454e0f9 (patch) | |
| tree | 1b95b0d7607426c66bd6173e0f1ff8c97a7b6541 /server/Server.hs | |
| parent | 252a4a3e1553295ffafbfa5150306f0f31dda8cd (diff) | |
sprinkle some NFData everywhere
(also some evaluateNF, leading to slightly less memory usage)
Diffstat (limited to 'server/Server.hs')
| -rw-r--r-- | server/Server.hs | 17 | 
1 files changed, 12 insertions, 5 deletions
diff --git a/server/Server.hs b/server/Server.hs index f89dc7b..f2b286b 100644 --- a/server/Server.hs +++ b/server/Server.hs @@ -3,6 +3,7 @@  {-# LANGUAGE DeriveAnyClass             #-}  {-# LANGUAGE DeriveGeneric              #-}  {-# LANGUAGE DerivingStrategies         #-} +{-# LANGUAGE FlexibleContexts           #-}  {-# LANGUAGE FlexibleInstances          #-}  {-# LANGUAGE GeneralizedNewtypeDeriving #-}  {-# LANGUAGE LambdaCase                 #-} @@ -15,6 +16,7 @@  {-# LANGUAGE TypeApplications           #-}  {-# LANGUAGE TypeFamilies               #-}  {-# LANGUAGE TypeOperators              #-} +{-# LANGUAGE UndecidableInstances       #-}  module Server ( loadConfig                , Org(..) @@ -57,7 +59,7 @@ data RemoteRef = RemoteRef    , reporef  :: Text    , reponame :: Text    -- ^ the "world name" for the hub / world:// links -  } deriving (Generic, FromJSON, ToJSON, Eq, Ord, Show) +  } deriving (Generic, FromJSON, ToJSON, Eq, Ord, Show, NFData)  type family ConfigRes (b :: Bool) a where    ConfigRes True a = a @@ -65,7 +67,7 @@ type family ConfigRes (b :: Bool) a where  -- | the internal text is actually already base64-encoded  newtype Sha1 = Sha1 Text -  deriving newtype (Eq, Show, Ord, FromHttpApiData, ToJSON) +  deriving newtype (Eq, Show, Ord, FromHttpApiData, ToJSON, NFData)  -- | base64-encoded sha1  prettySha :: Sha1 -> Text @@ -88,7 +90,9 @@ data Org (loaded :: Bool) = Org    , orgRepos      :: [RemoteRef]    , orgUrl        :: Text    , orgWebdir     :: Text -  } deriving Generic +  } deriving (Generic) + +instance NFData LintConfig' => NFData (Org True)  -- | Orgs are compared via their slugs only  -- TODO: the server should probably refuse to start if two orgs have the @@ -159,7 +163,7 @@ configCodec = Config  -- | a job status (of a specific uuid)  data JobStatus =    Pending | Linted !DirResult Text | Failed Text -  deriving (Generic, ToJSON) +  deriving (Generic, ToJSON, NFData)  instance TS.Show JobStatus where    show = \case @@ -171,6 +175,9 @@ instance TS.Show JobStatus where  -- stuff in here, hence the newtype  newtype ServerState = ServerState    { _unState :: Map (Org True) (Map Sha1 (RemoteRef, JobStatus)) } +  deriving Generic + +instance NFData LintConfig' => NFData ServerState  makeLenses ''ServerState @@ -204,7 +211,7 @@ setJobStatus mvar !org !ref !status = do      -- will otherwise cause a thunk leak, since Data.Map is annoyingly un-strict      -- even in its strict variety. for some reason it also doesn't work when      -- moved inside the `over` though … -    _ <- evaluateWHNF (view (unState . ix org) state) +    _ <- evaluateNF (view (unState . ix org) state)      pure $ over (unState . ix org . at (toSha ref))                  (const $ Just (ref, status)) state  | 
