This commit is contained in:
Dmitry Zuikov 2024-09-11 06:55:03 +03:00
parent d4b603aaf6
commit 5e2dec479a
1 changed files with 21 additions and 10 deletions

View File

@ -401,8 +401,9 @@ refchanImport = do
-- TODO: assume-huge-list -- TODO: assume-huge-list
scanned <- listAllScanned 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 case u of
@ -419,6 +420,14 @@ refchanImport = do
AnnotatedHashRef _ href <- deserialiseOrFail @AnnotatedHashRef (LBS.fromStrict bs) AnnotatedHashRef _ href <- deserialiseOrFail @AnnotatedHashRef (LBS.fromStrict bs)
& toMPlus . either (const Nothing) Just & toMPlus . either (const Nothing) Just
if HS.member href scanned then do
atx <- readTVarIO accepts <&> fromMaybe mempty . HM.lookup txh
lift $ withState $ transactional do
insertScanned txh
for_ atx insertScanned
else do
-- FIXME: decrypt-tree -- FIXME: decrypt-tree
what <- runExceptT (readFromMerkle sto (SimpleKey (coerce href))) what <- runExceptT (readFromMerkle sto (SimpleKey (coerce href)))
<&> either (const Nothing) Just <&> either (const Nothing) Just
@ -428,18 +437,20 @@ refchanImport = do
& toMPlus & toMPlus
for_ exported $ \exported -> do for_ exported $ \exported -> do
atomically $ writeTQueue tq (txh, orig, exported) unless (HS.member href scanned) do
atomically $ writeTQueue tq (txh, orig, href, exported)
imported <- atomically $ flushTQueue tq imported <- atomically $ flushTQueue tq
withState $ transactional do 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 w <- readTVarIO ttsmap <&> fromMaybe (exportedWeight i) . HM.lookup h
let item = i { exportedWeight = w } let item = i { exportedWeight = w }
notice $ "import" <+> pretty (exportedKey item) <+> pretty (exportedWeight item) notice $ "import" <+> pretty (exportedKey item) <+> pretty (exportedWeight item)
insertFixmeExported item insertFixmeExported item
atx <- readTVarIO accepts <&> fromMaybe mempty . HM.lookup h atx <- readTVarIO accepts <&> fromMaybe mempty . HM.lookup h
insertScanned txh insertScanned txh
insertScanned href
for_ atx insertScanned for_ atx insertScanned