From 5e2dec479ad97c31bf4480d51360c4623f84cd59 Mon Sep 17 00:00:00 2001 From: Dmitry Zuikov Date: Wed, 11 Sep 2024 06:55:03 +0300 Subject: [PATCH] wip --- fixme-new/lib/Fixme/Run/Internal.hs | 31 +++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/fixme-new/lib/Fixme/Run/Internal.hs b/fixme-new/lib/Fixme/Run/Internal.hs index 2431bb19..8bf3c7b4 100644 --- a/fixme-new/lib/Fixme/Run/Internal.hs +++ b/fixme-new/lib/Fixme/Run/Internal.hs @@ -401,8 +401,9 @@ refchanImport = do -- TODO: assume-huge-list scanned <- listAllScanned + let isScanned = pure . not . (`HS.member` scanned) - walkRefChanTx @UNIX (pure . not . (`HS.member` scanned)) chan $ \txh u -> do + walkRefChanTx @UNIX isScanned chan $ \txh u -> do case u of @@ -419,27 +420,37 @@ refchanImport = do AnnotatedHashRef _ href <- deserialiseOrFail @AnnotatedHashRef (LBS.fromStrict bs) & toMPlus . either (const Nothing) Just - -- FIXME: decrypt-tree - what <- runExceptT (readFromMerkle sto (SimpleKey (coerce href))) - <&> either (const Nothing) Just - >>= toMPlus + if HS.member href scanned then do + atx <- readTVarIO accepts <&> fromMaybe mempty . HM.lookup txh + lift $ withState $ transactional do + insertScanned txh + for_ atx insertScanned - exported <- deserialiseOrFail @[FixmeExported] what - & toMPlus + else do - for_ exported $ \exported -> do - atomically $ writeTQueue tq (txh, orig, exported) + -- FIXME: decrypt-tree + what <- runExceptT (readFromMerkle sto (SimpleKey (coerce href))) + <&> either (const Nothing) Just + >>= toMPlus + + exported <- deserialiseOrFail @[FixmeExported] what + & toMPlus + + for_ exported $ \exported -> do + unless (HS.member href scanned) do + atomically $ writeTQueue tq (txh, orig, href, exported) imported <- atomically $ flushTQueue tq withState $ transactional do - for_ imported $ \(txh, h, i) -> do + for_ imported $ \(txh, h, href, i) -> do w <- readTVarIO ttsmap <&> fromMaybe (exportedWeight i) . HM.lookup h let item = i { exportedWeight = w } notice $ "import" <+> pretty (exportedKey item) <+> pretty (exportedWeight item) insertFixmeExported item atx <- readTVarIO accepts <&> fromMaybe mempty . HM.lookup h insertScanned txh + insertScanned href for_ atx insertScanned