From b454da8bf8f76e0c75a751a1a6cb93f480305199 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 30 May 2022 13:31:49 +1000 Subject: several enhancements - logging - sorting by date - adding enclosure - deterministic message id using md5 --- src/F2Md/Config.hs | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'src/F2Md/Config.hs') diff --git a/src/F2Md/Config.hs b/src/F2Md/Config.hs index ef209dc..46a9a75 100644 --- a/src/F2Md/Config.hs +++ b/src/F2Md/Config.hs @@ -4,8 +4,10 @@ module F2Md.Config ( getUserdata , FeedUserdata(..) , updateLastUpdated + , updateLastUpdated' ) where +import Control.Monad import Data.List import F2Md.Utils import F2Md.Types @@ -48,24 +50,18 @@ getLastUpdatedMap :: FilePath -> IO (HM.HashMap Text ZonedTime) getLastUpdatedMap dbPath = fromMaybe (HM.fromList []) <$> (decodeFileStrict =<< expandPath dbPath) -updateLastUpdated :: FilePath -> [FeedUserdata] -> [[Message]] -> IO () -updateLastUpdated path feeds feedMsgs = do +updateLastUpdated' :: FilePath -> FeedUserdata -> [Message] -> IO () +updateLastUpdated' path feed msgs = + unless (null msgs) $ do decoded <- getLastUpdatedMap path - encodeFile path $ foldl' - (\hm (feed, msgs) -> - case msgs of - [] -> hm - h : _ -> HM.insert (fuUrl feed) - (utcToZonedTime (zonedTimeZone $ mDate h) . maximum $ + encodeFile path $ + HM.insert + (fuUrl feed) + (utcToZonedTime (zonedTimeZone $ mDate $ head msgs) . maximum $ (zonedTimeToUTC . mDate) <$> msgs) - hm) - decoded (zip feeds feedMsgs) - -- HM.fromList $ - -- mapMaybe - -- (\(feed, msgs) -> - -- case msgs of - -- [] -> fuLastUpdated feed >>= \date -> return (fuUrl feed, date) - -- h : _ -> - -- Just (fuUrl feed, - -- utcToZonedTime (zonedTimeZone $ mDate h) . maximum $ - -- (zonedTimeToUTC . mDate) <$> msgs)) $ zip feeds feedMsgs + decoded + +updateLastUpdated :: FilePath -> [FeedUserdata] -> [[Message]] -> IO () +updateLastUpdated path feeds feedMsgs = do + mapM_ (\(feed, msgs) -> updateLastUpdated' path feed msgs) + (zip feeds feedMsgs) -- cgit v1.2.3