Skip to content

Commit 272cf1c

Browse files
committed
WIP
1 parent 2ac3e3b commit 272cf1c

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/Share/Postgres/Sync/Queries.hs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ module Share.Postgres.Sync.Queries
1515
)
1616
where
1717

18-
import Codec.CBOR.Write qualified as CBOR
19-
import Codec.Serialise.Class qualified as CBOR
2018
import Control.Lens hiding (from)
2119
import Data.ByteString.Lazy.Char8 qualified as BL
2220
import Data.Foldable qualified as Foldable
@@ -66,7 +64,8 @@ import Unison.Hash32
6664
import Unison.Hash32 qualified as Hash32
6765
import Unison.Sync.Common qualified as Share
6866
import Unison.Sync.Types qualified as Share
69-
import Unison.SyncV2.Types (EntityKind (..))
67+
import Unison.SyncV2.Types (CBORBytes (..), EntityKind (..))
68+
import Unison.SyncV2.Types qualified as SyncV2
7069

7170
data SyncQError
7271
= InvalidNamespaceBytes
@@ -585,48 +584,48 @@ getEntitiesReadyToFlush = do
585584
saveSerializedEntities :: (Foldable f) => f (Hash32, TempEntity) -> CodebaseM e ()
586585
saveSerializedEntities entities = do
587586
for_ entities \(hash, entity) -> do
588-
let serialised = CBOR.toStrictByteString (CBOR.encode hash <> CBOR.encode entity)
587+
let serialised = SyncV2.serialiseCBORBytes entity
589588
case entity of
590589
Entity.TC {} -> saveSerializedComponent hash serialised
591590
Entity.DC {} -> saveSerializedComponent hash serialised
592591
Entity.P {} -> saveSerializedPatch hash serialised
593592
Entity.C {} -> saveSerializedCausal hash serialised
594593
Entity.N {} -> saveSerializedNamespace hash serialised
595594

596-
saveSerializedComponent :: Hash32 -> ByteString -> CodebaseM e ()
597-
saveSerializedComponent hash serialised = do
595+
saveSerializedComponent :: Hash32 -> CBORBytes TempEntity -> CodebaseM e ()
596+
saveSerializedComponent hash (CBORBytes bytes) = do
598597
codebaseOwnerUserId <- asks Codebase.codebaseOwner
599-
bytesId <- DefnQ.ensureBytesIdsOf id serialised
598+
bytesId <- DefnQ.ensureBytesIdsOf id (BL.toStrict bytes)
600599
execute_
601600
[sql|
602601
INSERT INTO serialized_components (user_id, component_hash_id, bytes_id)
603602
VALUES (#{codebaseOwnerUserId}, (SELECT ch.id FROM component_hashes ch where ch.base32 = #{hash}), #{bytesId})
604603
ON CONFLICT DO NOTHING
605604
|]
606605

607-
saveSerializedPatch :: Hash32 -> ByteString -> CodebaseM e ()
608-
saveSerializedPatch hash serialised = do
609-
bytesId <- DefnQ.ensureBytesIdsOf id serialised
606+
saveSerializedPatch :: Hash32 -> CBORBytes TempEntity -> CodebaseM e ()
607+
saveSerializedPatch hash (CBORBytes bytes) = do
608+
bytesId <- DefnQ.ensureBytesIdsOf id (BL.toStrict bytes)
610609
execute_
611610
[sql|
612611
INSERT INTO serialized_patches (patch_id, bytes_id)
613612
VALUES ((SELECT p.id FROM patches p where p.hash = #{hash}), #{bytesId})
614613
ON CONFLICT DO NOTHING
615614
|]
616615

617-
saveSerializedCausal :: Hash32 -> ByteString -> CodebaseM e ()
618-
saveSerializedCausal hash serialised = do
619-
bytesId <- DefnQ.ensureBytesIdsOf id serialised
616+
saveSerializedCausal :: Hash32 -> CBORBytes TempEntity -> CodebaseM e ()
617+
saveSerializedCausal hash (CBORBytes bytes) = do
618+
bytesId <- DefnQ.ensureBytesIdsOf id (BL.toStrict bytes)
620619
execute_
621620
[sql|
622621
INSERT INTO serialized_causals (causal_id, bytes_id)
623622
VALUES ((SELECT c.id FROM causals c where c.hash = #{hash}), #{bytesId})
624623
ON CONFLICT DO NOTHING
625624
|]
626625

627-
saveSerializedNamespace :: Hash32 -> ByteString -> CodebaseM e ()
628-
saveSerializedNamespace hash serialised = do
629-
bytesId <- DefnQ.ensureBytesIdsOf id serialised
626+
saveSerializedNamespace :: Hash32 -> CBORBytes TempEntity -> CodebaseM e ()
627+
saveSerializedNamespace hash (CBORBytes bytes) = do
628+
bytesId <- DefnQ.ensureBytesIdsOf id (BL.toStrict bytes)
630629
execute_
631630
[sql|
632631
INSERT INTO serialized_namespaces (namespace_hash_id, bytes_id)

src/Share/Web/UCM/SyncStream/Impl.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ import UnliftIO.Async qualified as Async
3939
server :: Maybe UserId -> SyncV2.Routes WebAppServer
4040
server mayUserId =
4141
SyncV2.Routes
42-
{ downloadEntitiesStream = downloadEntitiesStreamImpl mayUserId,
43-
uploadEntitiesStream = undefined
42+
{ downloadEntitiesStream = downloadEntitiesStreamImpl mayUserId
4443
}
4544

4645
parseBranchRef :: SyncV2.BranchRef -> Either Text (Either ProjectReleaseShortHand ProjectBranchShortHand)

0 commit comments

Comments
 (0)