Przeglądaj źródła

fix(rtc): fix ref&card-one attr update

rcmerci 1 rok temu
rodzic
commit
ed62a4c700

+ 6 - 3
src/main/frontend/worker/rtc/remote_update.cljs

@@ -365,15 +365,18 @@
       [true false]
       (let [remote-block-uuid (if (coll? remote-v) (first remote-v) remote-v)]
         (when (not= local-v remote-block-uuid)
-          (when-let [db-id (:db/id (d/entity db [:block/uuid remote-block-uuid]))]
-            [[:db/add e k db-id]])))
+          (if (nil? remote-block-uuid)
+            [[:db/retract e k]]
+            (when-let [db-id (:db/id (d/entity db [:block/uuid remote-block-uuid]))]
+              [[:db/add e k db-id]]))))
+
       [false false]
       (let [remote-v* (if (coll? remote-v)
                         (first (map ldb/read-transit-str remote-v))
                         (ldb/read-transit-str remote-v))]
         (when (not= local-v remote-v*)
           (if (nil? remote-v*)
-            [[:db/retract e k local-v]]
+            [[:db/retract e k]]
             [[:db/add e k remote-v*]])))
 
       [false true]

+ 17 - 5
src/test/frontend/worker/rtc/remote_update_test.cljs

@@ -3,11 +3,13 @@
             [datascript.core :as d]
             [frontend.worker.rtc.remote-update :as subject]
             [logseq.db :as ldb]
-            [logseq.db.frontend.schema :as db-schema]))
+            [logseq.db.frontend.schema :as db-schema]
+            [logseq.db.sqlite.create-graph :as sqlite-create-graph]))
 
 (deftest remote-op-value->tx-data-test
   (let [[block-uuid ref-uuid1 ref-uuid2] (repeatedly random-uuid)
-        db (d/empty-db db-schema/schema-for-db-based-graph)]
+        db (d/db-with (d/empty-db db-schema/schema-for-db-based-graph)
+                      (sqlite-create-graph/build-db-initial-data {}))]
     (testing ":block/title"
       (let [db (d/db-with db [{:block/uuid block-uuid
                                :block/title "local-content"}])
@@ -49,6 +51,16 @@
                (set (#'subject/remote-op-value->tx-data db (d/entity db [:block/uuid block-uuid]) op-value))))))
     (testing ":block/updated-at"
       (let [db (d/db-with db [{:block/uuid block-uuid
-                               :block/updated-at 1}])]
-        (is (= [[:db/retract 1 :block/updated-at 1]]
-               (#'subject/remote-op-value->tx-data db (d/entity db [:block/uuid block-uuid]) {})))))))
+                               :block/updated-at 1}])
+            ent (d/entity db [:block/uuid block-uuid])]
+        (is (= [[:db/retract (:db/id ent) :block/updated-at]]
+               (#'subject/remote-op-value->tx-data db ent {})))))
+    (testing ":logseq.task/status, op-value don't have this attr, means remove this attr"
+      (let [db (d/db-with db [{:db/id "ref1"
+                               :block/uuid ref-uuid1}
+                              {:block/uuid block-uuid
+                               :logseq.task/status "ref1"}])
+            op-value {}
+            ent (d/entity db [:block/uuid block-uuid])]
+        (is (= [[:db/retract (:db/id ent) :logseq.task/status]]
+               (#'subject/remote-op-value->tx-data db ent op-value)))))))