Ver Fonte

enhance(rtc): :block/schema sync

rcmerci há 2 anos atrás
pai
commit
65edc47919

+ 4 - 12
src/main/frontend/db/rtc/const.cljs

@@ -5,21 +5,12 @@
             [malli.transform :as mt]))
 
 
-(def block-schema-schema
-  [:map {:closed false}
-   [:type :keyword]
-   [:cardinality {:optional true} [:enum :one :many]]
-   [:hide? {:optional true} :boolean]])
-
-(def block-schema-decoder (m/decoder block-schema-schema mt/string-transformer))
-
-
 (def general-attrs-schema-coll
   [[:updated-at {:optional true} :int]
    [:created-at {:optional true} :int]
    [:alias {:optional true} [:maybe [:sequential :uuid]]]
    [:type {:optional true} [:maybe [:sequential :string]]]
-   [:schema {:optional true} [:maybe block-schema-schema]]
+   [:schema {:optional true} [:maybe :string]]
    [:tags {:optional true} [:maybe [:sequential :uuid]]]
    [:properties {:optional true} [:maybe :string ; transit-json-string
                                   ]]])
@@ -104,9 +95,10 @@
       [:type {:optional true} [:map
                                [:add {:optional true} [:maybe [:set block-type-schema]]]
                                [:retract {:optional true} [:maybe [:set block-type-schema]]]]]
-      [:schema {:optional true} [:map-of :keyword :any]]
+      [:schema {:optional true} :string ;transit-string
+       ]
       [:properties {:optional true} [:map
-                                     [:add {:optional true} [:sequential [:cat :uuid :string ;; value is transit-json-string
+                                     [:add {:optional true} [:sequential [:cat :uuid :string ;; transit-string
                                                                           ]]]
                                      [:retract {:optional true} [:set :uuid]]]]]]]
    [:update-page

+ 7 - 5
src/main/frontend/db/rtc/core.cljs

@@ -185,7 +185,7 @@
                                                                                (db/pull-many repo [:db/id])
                                                                                (keep :db/id)))
               (contains? key-set :type)           (assoc :block/type (:type op-value))
-              (contains? key-set :schema)         (assoc :block/schema (:schema op-value))
+              (contains? key-set :schema)         (assoc :block/schema (transit/read transit-r (:schema op-value)))
               (contains? key-set :tags)           (assoc :block/tags (some->> (seq (:tags op-value))
                                                                               (map (partial vector :block/uuid))
                                                                               (db/pull-many repo [:db/id])
@@ -450,7 +450,7 @@
                                 (cond-> {:block-uuid block-uuid}
                                   (:block/updated-at b)       (assoc :updated-at (:block/updated-at b))
                                   (:block/created-at b)       (assoc :created-at (:block/created-at b))
-                                  (contains? key-set :schema) (assoc :schema (:block/schema b))
+                                  (contains? key-set :schema) (assoc :schema (transit/write transit-w (:block/schema b)))
                                   attr-type-map               (assoc :type attr-type-map)
                                   attr-alias-map              (assoc :alias attr-alias-map)
                                   attr-tags-map               (assoc :tags attr-tags-map)
@@ -492,9 +492,11 @@
               nil)
           ;; else
           (throw (ex-info "Unavailable" {:remote-ex remote-ex})))
-        (do (<! (p->c (op/<clean-ops repo op-keys)))
-            (<! (<apply-remote-data repo (rtc-const/data-from-ws-decoder r)))
-            (prn :<client-op-update-handler r))))))
+        (do (assert (pos? (:t r)) r)
+            (<! (p->c (op/<clean-ops repo op-keys)))
+            (<! (p->c (op/<update-local-tx! repo (:t r))))
+            ;; (<! (<apply-remote-data repo (rtc-const/data-from-ws-decoder r)))
+            (prn :<client-op-update-handler :t (:t r)))))))
 
 (defn- make-push-client-ops-timeout-ch
   [repo never-timeout?]

+ 3 - 7
src/main/frontend/db/rtc/full_upload_download_graph.cljs

@@ -12,9 +12,7 @@
             [logseq.db.frontend.schema :as db-schema]
             [frontend.persist-db :as persist-db]
             [frontend.db.rtc.op :as op]
-            [logseq.outliner.pipeline :as outliner-pipeline]
-            [cljs.reader :as reader]
-            [frontend.db.rtc.const :as rtc-const]))
+            [logseq.outliner.pipeline :as outliner-pipeline]))
 
 (def transit-r (transit/reader :json))
 
@@ -75,8 +73,7 @@
            block-tags (map :db/id (:block/tags block))
            block-type (keep (comp block-type-ident->str :db/ident) (:block/type block))
            block-schema (some->> (:block/schema block)
-                                 reader/read-string
-                                 rtc-const/block-schema-decoder)
+                                 (transit/read transit-r))
            block-properties (some->> (:block/properties block)
                                      (transit/read transit-r))]
        ;; TODO: block/properties
@@ -142,8 +139,7 @@
           repo (str "logseq_db_rtc-" repo)]
       (if (not= 200 status)
         (ex-info "<download-graph failed" r)
-        (let [reader (transit/reader :json)
-              all-blocks (transit/read reader body)]
+        (let [all-blocks (transit/read transit-r body)]
           (<! (<transact-remote-all-blocks-to-sqlite all-blocks repo))
           (<! (p->c (op/<update-graph-uuid! repo graph-uuid))))))))