Skip to content

Commit 1f5ffa5

Browse files
committed
SyncV2 cleanup
1 parent 5d8e60e commit 1f5ffa5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

unison-cli/src/Unison/Share/SyncV2.hs

+9-9
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ import UnliftIO qualified as IO
6666

6767
type Stream i o = ConduitT i o StreamM ()
6868

69-
type PullErr = SyncError SyncV2.PullError
69+
type SyncErr = SyncError SyncV2.PullError
7070

71-
type StreamM = (ExceptT PullErr (C.ResourceT IO))
71+
type StreamM = (ExceptT SyncErr (C.ResourceT IO))
7272

7373
batchSize :: Int
7474
batchSize = 5000
@@ -115,7 +115,7 @@ syncSortedStream codebase stream = do
115115
validateAndSave codebase (catMaybes entityBatch)
116116
C.runConduit $ stream C..| C.chunksOf batchSize C..| handler
117117

118-
unpackChunk :: SyncV2.EntityChunk -> ExceptT PullErr Sqlite.Transaction (Maybe (Hash32, TempEntity))
118+
unpackChunk :: SyncV2.EntityChunk -> ExceptT SyncErr Sqlite.Transaction (Maybe (Hash32, TempEntity))
119119
unpackChunk = \case
120120
SyncV2.EntityChunk {hash, entityCBOR = entityBytes} -> do
121121
-- Only want entities we don't already have
@@ -124,18 +124,18 @@ unpackChunk = \case
124124
_ -> do
125125
(Just . (hash,)) <$> unpackEntity entityBytes
126126
where
127-
unpackEntity :: (CBORBytes TempEntity) -> ExceptT PullErr Sqlite.Transaction TempEntity
127+
unpackEntity :: (CBORBytes TempEntity) -> ExceptT SyncErr Sqlite.Transaction TempEntity
128128
unpackEntity entityBytes = do
129129
case CBOR.deserialiseOrFailCBORBytes entityBytes of
130130
Left err -> do throwError $ (SyncError . SyncV2.PullError'Sync $ SyncV2.SyncErrorDeserializationFailure err)
131131
Right entity -> pure entity
132132

133-
unpackChunks :: [SyncV2.EntityChunk] -> ExceptT PullErr Sqlite.Transaction [(Hash32, TempEntity)]
133+
unpackChunks :: [SyncV2.EntityChunk] -> ExceptT SyncErr Sqlite.Transaction [(Hash32, TempEntity)]
134134
unpackChunks xs = do
135135
for xs unpackChunk
136136
<&> catMaybes
137137

138-
batchValidateEntities :: [(Hash32, TempEntity)] -> ExceptT PullErr IO ()
138+
batchValidateEntities :: [(Hash32, TempEntity)] -> ExceptT SyncErr IO ()
139139
batchValidateEntities entities = do
140140
mismatches <- fmap catMaybes $ liftIO $ IO.pooledForConcurrently entities \(hash, entity) -> do
141141
IO.evaluate $ EV.validateTempEntity hash entity
@@ -281,7 +281,7 @@ syncToFile ::
281281
CausalHash ->
282282
Maybe SyncV2.BranchRef ->
283283
FilePath ->
284-
IO (Either PullErr ())
284+
IO (Either SyncErr ())
285285
syncToFile codebase rootHash mayBranchRef destFilePath = do
286286
liftIO $ Codebase.withConnection codebase \conn -> do
287287
liftIO . C.runResourceT . runExceptT $ withEntityStream conn rootHash mayBranchRef \stream -> do
@@ -327,13 +327,13 @@ decodeUnframedEntities = C.transPipe (mapExceptT (lift . stToIO)) $ do
327327
d <- newDecoder
328328
loop bs d
329329
where
330-
newDecoder :: ConduitT ByteString SyncV2.DownloadEntitiesChunk (ExceptT PullErr (ST s)) (Maybe ByteString -> ST s (CBOR.IDecode s (SyncV2.DownloadEntitiesChunk)))
330+
newDecoder :: ConduitT ByteString SyncV2.DownloadEntitiesChunk (ExceptT SyncErr (ST s)) (Maybe ByteString -> ST s (CBOR.IDecode s (SyncV2.DownloadEntitiesChunk)))
331331
newDecoder = do
332332
(lift . lift) CBOR.deserialiseIncremental >>= \case
333333
CBOR.Done _ _ _ -> throwError . SyncError . SyncV2.PullError'Sync $ SyncV2.SyncErrorStreamFailure "Invalid initial decoder"
334334
CBOR.Fail _ _ err -> throwError . SyncError . SyncV2.PullError'Sync $ SyncV2.SyncErrorDeserializationFailure err
335335
CBOR.Partial k -> pure k
336-
loop :: ByteString -> (Maybe ByteString -> ST s (CBOR.IDecode s (SyncV2.DownloadEntitiesChunk))) -> ConduitT ByteString SyncV2.DownloadEntitiesChunk (ExceptT PullErr (ST s)) ()
336+
loop :: ByteString -> (Maybe ByteString -> ST s (CBOR.IDecode s (SyncV2.DownloadEntitiesChunk))) -> ConduitT ByteString SyncV2.DownloadEntitiesChunk (ExceptT SyncErr (ST s)) ()
337337
loop bs k = do
338338
(lift . lift) (k (Just bs)) >>= \case
339339
CBOR.Fail _ _ err -> throwError . SyncError . SyncV2.PullError'Sync $ SyncV2.SyncErrorDeserializationFailure err

0 commit comments

Comments
 (0)