core: use Int64 in time calculations (#2143)

* core: use Int64 in time calculations

* remove import

* make interval Int64
This commit is contained in:
Evgeny Poberezkin
2023-04-04 14:26:31 +01:00
committed by GitHub
parent 12fb2a4ec5
commit 2148d50393
6 changed files with 10 additions and 32 deletions
+4 -5
View File
@@ -57,7 +57,6 @@ import Simplex.Chat.ProfileGenerator (generateRandomProfile)
import Simplex.Chat.Protocol
import Simplex.Chat.Store
import Simplex.Chat.Types
import Simplex.Chat.Util (diffInMicros, diffInSeconds)
import Simplex.FileTransfer.Client.Presets (defaultXFTPServers)
import Simplex.FileTransfer.Description (ValidFileDescription, gb, kb, mb)
import Simplex.FileTransfer.Protocol (FileParty (..))
@@ -1778,7 +1777,7 @@ startExpireCIThread user@User {userId} = do
atomically $ TM.lookup userId expireFlags >>= \b -> unless (b == Just True) retry
ttl <- withStore' (`getChatItemTTL` user)
forM_ ttl $ \t -> expireChatItems user t False
threadDelay interval
liftIO $ threadDelay' interval
setExpireCIFlag :: ChatMonad' m => User -> Bool -> m ()
setExpireCIFlag User {userId} b = do
@@ -2174,7 +2173,7 @@ subscribeUserConnections agentBatchSubscribe user = do
Just _ -> Nothing
_ -> Just . ChatError . CEAgentNoSubResult $ AgentConnId connId
cleanupManagerInterval :: Int
cleanupManagerInterval :: Int64
cleanupManagerInterval = 1800 -- 30 minutes
cleanupManager :: forall m. ChatMonad m => m ()
@@ -2186,7 +2185,7 @@ cleanupManager = do
let (us, us') = partition activeUser users
forM_ us cleanupUser
forM_ us' cleanupUser
threadDelay $ cleanupManagerInterval * 1000000
liftIO $ threadDelay' $ cleanupManagerInterval * 1000000
where
cleanupUser user =
cleanupTimedItems user `catchError` (toView . CRChatError (Just user))
@@ -2220,7 +2219,7 @@ startTimedItemThread user itemRef deleteAt = do
deleteTimedItem :: ChatMonad m => User -> (ChatRef, ChatItemId) -> UTCTime -> m ()
deleteTimedItem user (ChatRef cType chatId, itemId) deleteAt = do
ts <- liftIO getCurrentTime
threadDelay $ diffInMicros deleteAt ts
liftIO $ threadDelay' $ diffInMicros deleteAt ts
waitChatStarted
case cType of
CTDirect -> do
+1 -1
View File
@@ -113,7 +113,7 @@ data ChatConfig = ChatConfig
hostEvents :: Bool,
logLevel :: ChatLogLevel,
testView :: Bool,
ciExpirationInterval :: Int -- microseconds
ciExpirationInterval :: Int64 -- microseconds
}
data DefaultAgentServers = DefaultAgentServers
+2 -23
View File
@@ -1,27 +1,6 @@
{-# LANGUAGE NumericUnderscores #-}
module Simplex.Chat.Util (week) where
module Simplex.Chat.Util
( diffInMicros,
diffInSeconds,
week,
)
where
import Data.Fixed (Fixed (MkFixed), Pico)
import Data.Time (NominalDiffTime, nominalDiffTimeToSeconds)
import Data.Time.Clock (UTCTime, diffUTCTime)
diffInSeconds :: UTCTime -> UTCTime -> Int
diffInSeconds a b = (`div` 1000000_000000) $ diffInPicos a b
diffInMicros :: UTCTime -> UTCTime -> Int
diffInMicros a b = (`div` 1000000) $ diffInPicos a b
diffInPicos :: UTCTime -> UTCTime -> Int
diffInPicos a b = fromInteger . fromPico . nominalDiffTimeToSeconds $ diffUTCTime a b
fromPico :: Pico -> Integer
fromPico (MkFixed i) = i
import Data.Time (NominalDiffTime)
week :: NominalDiffTime
week = 7 * 86400