diff options
Diffstat (limited to 'src/F2Md/Config.hs')
-rw-r--r-- | src/F2Md/Config.hs | 34 |
1 files changed, 15 insertions, 19 deletions
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) |