From 640f6fdfe4d675427df151fc3405fa3f2ca7c029 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Fri, 20 Oct 2023 14:09:53 +0200 Subject: [PATCH] fix(users/Profpatsch/openlab-tools): really deepseq cache content Okay, so I guess you also have to seq the cache and everything in between the IORef and the data. Change-Id: I4c79c99afbd09e83e9d7a01d58b31b36862e4d11 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9807 Reviewed-by: Profpatsch Autosubmit: Profpatsch Tested-by: BuildkiteCI --- users/Profpatsch/openlab-tools/src/OpenlabTools.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/users/Profpatsch/openlab-tools/src/OpenlabTools.hs b/users/Profpatsch/openlab-tools/src/OpenlabTools.hs index b63b6a601..21909368b 100644 --- a/users/Profpatsch/openlab-tools/src/OpenlabTools.hs +++ b/users/Profpatsch/openlab-tools/src/OpenlabTools.hs @@ -251,8 +251,8 @@ assertM span f v = case f v of Left err -> appThrowTree span err data Cache a = Cache - { until :: UTCTime, - result :: a + { until :: !UTCTime, + result :: !a } newCache :: a -> IO (IORef (Cache a)) @@ -262,10 +262,10 @@ newCache 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' + -- make sure we don’t hold onto the world by deepseq-ing and evaluating to WHNF + let !result = deepseq result' result' until <- getCurrentTime <&> ((5 * 60) `addUTCTime`) - _ <- writeIORef cache Cache {..} + _ <- writeIORef cache $! Cache {..} pure () updateCacheIfNewer :: (MonadUnliftIO m, NFData b) => IORef (Cache b) -> m b -> m b