Skip to content

Commit 58d3c16

Browse files
authored
smp server: fix logging progress when importing journal (#1393)
1 parent 326cf08 commit 58d3c16

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Simplex/Messaging/Server.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,9 +1796,9 @@ processServerMessages = do
17961796
importMessages :: forall s. MsgStoreClass s => Bool -> s -> FilePath -> Maybe Int64 -> IO MessageStats
17971797
importMessages tty ms f old_ = do
17981798
logInfo $ "restoring messages from file " <> T.pack f
1799-
LB.readFile f >>= runExceptT . foldM restoreMsg (0, Nothing, (0, 0, M.empty)) . zip [0..] . LB.lines >>= \case
1799+
LB.readFile f >>= runExceptT . foldM restoreMsg (0, Nothing, (0, 0, M.empty)) . LB.lines >>= \case
18001800
Left e -> do
1801-
putStrLn ""
1801+
when tty $ putStrLn ""
18021802
logError . T.pack $ "error restoring messages: " <> e
18031803
liftIO exitFailure
18041804
Right (lineCount, _, (storedMsgsCount, expiredMsgsCount, overQuota)) -> do
@@ -1810,9 +1810,9 @@ importMessages tty ms f old_ = do
18101810
pure MessageStats {storedMsgsCount, expiredMsgsCount, storedQueues}
18111811
where
18121812
progress i = "Processed " <> show i <> " lines"
1813-
restoreMsg :: (Int, Maybe (RecipientId, MsgQueue s), (Int, Int, M.Map RecipientId (MsgQueue s))) -> (Int, LB.ByteString) -> ExceptT String IO (Int, Maybe (RecipientId, MsgQueue s), (Int, Int, M.Map RecipientId (MsgQueue s)))
1814-
restoreMsg (!lineCount, q_, (!stored, !expired, !overQuota)) (i, s') = do
1815-
when (tty && i `mod` 1000 == 0) $ liftIO $ putStr (progress i <> "\r")
1813+
restoreMsg :: (Int, Maybe (RecipientId, MsgQueue s), (Int, Int, M.Map RecipientId (MsgQueue s))) -> LB.ByteString -> ExceptT String IO (Int, Maybe (RecipientId, MsgQueue s), (Int, Int, M.Map RecipientId (MsgQueue s)))
1814+
restoreMsg (!i, q_, (!stored, !expired, !overQuota)) s' = do
1815+
when (tty && i `mod` 1000 == 0) $ liftIO $ putStr (progress i <> "\r") >> hFlush stdout
18161816
MLRv3 rId msg <- liftEither . first (msgErr "parsing") $ strDecode s
18171817
liftError show $ addToMsgQueue rId msg
18181818
where
@@ -1822,7 +1822,7 @@ importMessages tty ms f old_ = do
18221822
-- to avoid lookup when restoring the next message to the same queue
18231823
Just (rId', q') | rId' == rId -> pure q'
18241824
_ -> getMsgQueue ms rId
1825-
(lineCount + 1,Just (rId, q),) <$> case msg of
1825+
(i + 1,Just (rId, q),) <$> case msg of
18261826
Message {msgTs}
18271827
| maybe True (systemSeconds msgTs >=) old_ -> do
18281828
writeMsg ms q False msg >>= \case

0 commit comments

Comments
 (0)