@@ -15,8 +15,6 @@ module Share.Postgres.Sync.Queries
15
15
)
16
16
where
17
17
18
- import Codec.CBOR.Write qualified as CBOR
19
- import Codec.Serialise.Class qualified as CBOR
20
18
import Control.Lens hiding (from )
21
19
import Data.ByteString.Lazy.Char8 qualified as BL
22
20
import Data.Foldable qualified as Foldable
@@ -66,7 +64,8 @@ import Unison.Hash32
66
64
import Unison.Hash32 qualified as Hash32
67
65
import Unison.Sync.Common qualified as Share
68
66
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
70
69
71
70
data SyncQError
72
71
= InvalidNamespaceBytes
@@ -585,48 +584,48 @@ getEntitiesReadyToFlush = do
585
584
saveSerializedEntities :: (Foldable f ) => f (Hash32 , TempEntity ) -> CodebaseM e ()
586
585
saveSerializedEntities entities = do
587
586
for_ entities \ (hash, entity) -> do
588
- let serialised = CBOR. toStrictByteString ( CBOR. encode hash <> CBOR. encode entity)
587
+ let serialised = SyncV2. serialiseCBORBytes entity
589
588
case entity of
590
589
Entity. TC {} -> saveSerializedComponent hash serialised
591
590
Entity. DC {} -> saveSerializedComponent hash serialised
592
591
Entity. P {} -> saveSerializedPatch hash serialised
593
592
Entity. C {} -> saveSerializedCausal hash serialised
594
593
Entity. N {} -> saveSerializedNamespace hash serialised
595
594
596
- saveSerializedComponent :: Hash32 -> ByteString -> CodebaseM e ()
597
- saveSerializedComponent hash serialised = do
595
+ saveSerializedComponent :: Hash32 -> CBORBytes TempEntity -> CodebaseM e ()
596
+ saveSerializedComponent hash ( CBORBytes bytes) = do
598
597
codebaseOwnerUserId <- asks Codebase. codebaseOwner
599
- bytesId <- DefnQ. ensureBytesIdsOf id serialised
598
+ bytesId <- DefnQ. ensureBytesIdsOf id ( BL. toStrict bytes)
600
599
execute_
601
600
[sql |
602
601
INSERT INTO serialized_components (user_id, component_hash_id, bytes_id)
603
602
VALUES (#{codebaseOwnerUserId}, (SELECT ch.id FROM component_hashes ch where ch.base32 = #{hash}), #{bytesId})
604
603
ON CONFLICT DO NOTHING
605
604
|]
606
605
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)
610
609
execute_
611
610
[sql |
612
611
INSERT INTO serialized_patches (patch_id, bytes_id)
613
612
VALUES ((SELECT p.id FROM patches p where p.hash = #{hash}), #{bytesId})
614
613
ON CONFLICT DO NOTHING
615
614
|]
616
615
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)
620
619
execute_
621
620
[sql |
622
621
INSERT INTO serialized_causals (causal_id, bytes_id)
623
622
VALUES ((SELECT c.id FROM causals c where c.hash = #{hash}), #{bytesId})
624
623
ON CONFLICT DO NOTHING
625
624
|]
626
625
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)
630
629
execute_
631
630
[sql |
632
631
INSERT INTO serialized_namespaces (namespace_hash_id, bytes_id)
0 commit comments