hbs2 metadata create preformance fix

This commit is contained in:
Dmitry Zuikov 2024-06-17 06:34:38 +03:00
parent 9aafab745d
commit 557e0f1b90
1 changed files with 13 additions and 7 deletions

View File

@ -21,6 +21,7 @@ import Streaming qualified as S
import Data.Function import Data.Function
import Control.Monad.Except import Control.Monad.Except
import Control.Exception
import Data.Bifunctor import Data.Bifunctor
import Data.ByteString.Lazy (ByteString) import Data.ByteString.Lazy (ByteString)
import Data.ByteString.Lazy qualified as LBS import Data.ByteString.Lazy qualified as LBS
@ -28,17 +29,22 @@ import Data.ByteString.Lazy qualified as LBS
-- importimport Data.List.Split (chunksOf) -- importimport Data.List.Split (chunksOf)
data WriteMerkleIOError =
WriteMerkleIOError
deriving (Show,Typeable,Generic)
instance Exception WriteMerkleIOError
instance (MonadIO m, h ~ HbSync, Storage s h ByteString m) => MerkleWriter ByteString h s m where instance (MonadIO m, h ~ HbSync, Storage s h ByteString m) => MerkleWriter ByteString h s m where
type instance ToBlockW ByteString = ByteString type instance ToBlockW ByteString = ByteString
writeAsMerkle sto bs = do writeAsMerkle sto bs = do
hashes <- S.each (LBS.unpack bs) hashes <- do
& S.chunksOf (fromIntegral defBlockSize ) chu <- S.toList_ (readChunkedBS bs defBlockSize)
& S.mapped (fmap (first LBS.pack) . S.toList) for chu $ \chunk -> do
& S.mapM (\blk -> enqueueBlock sto blk >> pure blk) enqueueBlock sto chunk
-- & S.mapM (\blk -> putBlock sto blk >> pure blk) >>= liftIO . maybe (throwIO WriteMerkleIOError) (pure . HashRef)
& S.map (HashRef . hashObject)
& S.toList_
-- FIXME: handle-hardcode -- FIXME: handle-hardcode
let pt = toPTree (MaxSize defHashListChunk) (MaxNum defTreeChildNum) hashes -- FIXME: settings let pt = toPTree (MaxSize defHashListChunk) (MaxNum defTreeChildNum) hashes -- FIXME: settings