diff options
author | Profpatsch <mail@profpatsch.de> | 2023-10-20T11·58+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-10-20T12·02+0000 |
commit | 3dba987de4623d903fc6e7d05550b37e57711cdd (patch) | |
tree | 922e71639a4dc7902b158822eaae2cc2f9261d02 /users/Profpatsch/openlab-tools/src | |
parent | c2893a5c77933e0d2893dc8aee2d50574ab321df (diff) |
fix(users/Profpatsch/openlab-tools): deepseq cache content r/6861
Otherwise the table might potentially hold onto data from the website request, it’s hard to say. Change-Id: I786478bd1ce2d9775b3d0b57565d79666ef8a96f Reviewed-on: https://cl.tvl.fyi/c/depot/+/9806 Autosubmit: Profpatsch <mail@profpatsch.de> Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch/openlab-tools/src')
-rw-r--r-- | users/Profpatsch/openlab-tools/src/OpenlabTools.hs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/users/Profpatsch/openlab-tools/src/OpenlabTools.hs b/users/Profpatsch/openlab-tools/src/OpenlabTools.hs index 056d2a5d221d..b63b6a601200 100644 --- a/users/Profpatsch/openlab-tools/src/OpenlabTools.hs +++ b/users/Profpatsch/openlab-tools/src/OpenlabTools.hs @@ -5,6 +5,7 @@ module OpenlabTools where +import Control.DeepSeq (NFData, deepseq) import Control.Monad.Logger qualified as Logger import Control.Monad.Logger.CallStack import Control.Monad.Reader @@ -259,13 +260,15 @@ newCache result = do until <- getCurrentTime newIORef Cache {..} -updateCache :: IORef (Cache a) -> a -> IO () -updateCache cache result = do +updateCache :: (NFData a) => IORef (Cache a) -> a -> IO () +updateCache cache result' = do + -- make sure we don’t hold onto the world by deepseq-ing + let result = deepseq result' result' until <- getCurrentTime <&> ((5 * 60) `addUTCTime`) _ <- writeIORef cache Cache {..} pure () -updateCacheIfNewer :: (MonadUnliftIO m) => IORef (Cache b) -> m b -> m b +updateCacheIfNewer :: (MonadUnliftIO m, NFData b) => IORef (Cache b) -> m b -> m b updateCacheIfNewer cache act = withRunInIO $ \runInIO -> do old <- readIORef cache now <- getCurrentTime @@ -273,6 +276,7 @@ updateCacheIfNewer cache act = withRunInIO $ \runInIO -> do then do res <- runInIO act updateCache cache res + pure res else pure old.result |