From 2148d5039394c440498624ab2abc7d5a2938c003 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Tue, 4 Apr 2023 14:26:31 +0100 Subject: [PATCH] core: use Int64 in time calculations (#2143) * core: use Int64 in time calculations * remove import * make interval Int64 --- cabal.project | 2 +- scripts/nix/sha256map.nix | 2 +- src/Simplex/Chat.hs | 9 ++++----- src/Simplex/Chat/Controller.hs | 2 +- src/Simplex/Chat/Util.hs | 25 ++----------------------- stack.yaml | 2 +- 6 files changed, 10 insertions(+), 32 deletions(-) diff --git a/cabal.project b/cabal.project index e925083a69..70e49997ad 100644 --- a/cabal.project +++ b/cabal.project @@ -7,7 +7,7 @@ constraints: zip +disable-bzip2 +disable-zstd source-repository-package type: git location: https://github.com/simplex-chat/simplexmq.git - tag: c6033e51a04b66523ab4580c067b8cb0b87fd452 + tag: 44f0dd39f3d1536c979b09e268dbdf681f9b0bb8 source-repository-package type: git diff --git a/scripts/nix/sha256map.nix b/scripts/nix/sha256map.nix index b7889cc47c..9bda59a752 100644 --- a/scripts/nix/sha256map.nix +++ b/scripts/nix/sha256map.nix @@ -1,5 +1,5 @@ { - "https://github.com/simplex-chat/simplexmq.git"."c6033e51a04b66523ab4580c067b8cb0b87fd452" = "119fyks79dn1z73r1y259aagcw31hrpdlmx1wqip6i0p5bgbs6vj"; + "https://github.com/simplex-chat/simplexmq.git"."44f0dd39f3d1536c979b09e268dbdf681f9b0bb8" = "0dh0q2vng374kkq8s1lnnv658xfv6q7b9cgshiqxs9hxij64kxav"; "https://github.com/simplex-chat/hs-socks.git"."a30cc7a79a08d8108316094f8f2f82a0c5e1ac51" = "0yasvnr7g91k76mjkamvzab2kvlb1g5pspjyjn2fr6v83swjhj38"; "https://github.com/kazu-yamamoto/http2.git"."159417b413a684a9b754e10e4a5db4376aa8c6b9" = "17jjw582f4ls1m14abym1p0xlpjx1viqsfcpl4fkykv0sksbxdg7"; "https://github.com/simplex-chat/direct-sqlcipher.git"."34309410eb2069b029b8fc1872deb1e0db123294" = "0kwkmhyfsn2lixdlgl15smgr1h5gjk7fky6abzh8rng2h5ymnffd"; diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index c40f6bc205..aeb3bca556 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -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 diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index c8fa158280..94db939f21 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -113,7 +113,7 @@ data ChatConfig = ChatConfig hostEvents :: Bool, logLevel :: ChatLogLevel, testView :: Bool, - ciExpirationInterval :: Int -- microseconds + ciExpirationInterval :: Int64 -- microseconds } data DefaultAgentServers = DefaultAgentServers diff --git a/src/Simplex/Chat/Util.hs b/src/Simplex/Chat/Util.hs index b5c3c8277a..7a350705f1 100644 --- a/src/Simplex/Chat/Util.hs +++ b/src/Simplex/Chat/Util.hs @@ -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 diff --git a/stack.yaml b/stack.yaml index 3dff23ce2c..9a24921cee 100644 --- a/stack.yaml +++ b/stack.yaml @@ -49,7 +49,7 @@ extra-deps: # - simplexmq-1.0.0@sha256:34b2004728ae396e3ae449cd090ba7410781e2b3cefc59259915f4ca5daa9ea8,8561 # - ../simplexmq - github: simplex-chat/simplexmq - commit: c6033e51a04b66523ab4580c067b8cb0b87fd452 + commit: 44f0dd39f3d1536c979b09e268dbdf681f9b0bb8 - github: kazu-yamamoto/http2 commit: 159417b413a684a9b754e10e4a5db4376aa8c6b9 # - ../direct-sqlcipher