Browse Source

fix(rtc): missing create-by-ref

rcmerci 5 months ago
parent
commit
e5a4417838

+ 5 - 5
src/main/frontend/worker/db_listener.cljs

@@ -31,11 +31,11 @@
 
       (when-not from-disk?
         (p/do!
-         (let [{:keys [blocks-to-remove-set blocks-to-add]} (search/sync-search-indice repo tx-report')]
-           (when (seq blocks-to-remove-set)
-             ((@thread-api/*thread-apis :thread-api/search-delete-blocks) repo blocks-to-remove-set))
-           (when (seq blocks-to-add)
-             ((@thread-api/*thread-apis :thread-api/search-upsert-blocks) repo blocks-to-add))))))
+          (let [{:keys [blocks-to-remove-set blocks-to-add]} (search/sync-search-indice repo tx-report')]
+            (when (seq blocks-to-remove-set)
+              ((@thread-api/*thread-apis :thread-api/search-delete-blocks) repo blocks-to-remove-set))
+            (when (seq blocks-to-add)
+              ((@thread-api/*thread-apis :thread-api/search-upsert-blocks) repo blocks-to-add))))))
     tx-report'))
 
 (comment

+ 5 - 2
src/main/frontend/worker/pipeline.cljs

@@ -184,7 +184,8 @@
 
 (defn- add-created-by-ref-hook
   [db-before db-after tx-data tx-meta]
-  (when (and (not (or (:undo? tx-meta) (:redo? tx-meta) (:rtc-tx? tx-meta)))
+  (when (and (not (or (:undo? tx-meta) (:redo? tx-meta)
+                      (:rtc-tx? tx-meta) (:rtc-download-graph? tx-meta)))
              (seq tx-data))
     (when-let [decoded-id-token (some-> (worker-state/get-id-token) worker-util/parse-jwt)]
       (let [created-by-ent (d/entity db-after [:block/uuid (uuid (:sub decoded-id-token))])
@@ -208,7 +209,9 @@
                    ;; update created-by when block change from empty-block-title to non-empty
                    (and (keyword-identical? :block/title attr)
                         (not (string/blank? value))
-                        (string/blank? (:block/title (d/entity db-before e))))
+                        (let [origin-title (:block/title (d/entity db-before e))]
+                          (and (some? origin-title)
+                               (string/blank? origin-title))))
                    [:db/add e :logseq.property/created-by-ref created-by-id])))
              tx-data)]
         (cond->> add-created-by-tx-data

+ 1 - 1
src/main/frontend/worker/rtc/core.cljs

@@ -200,7 +200,7 @@
 (def ^:private *graph-uuid->*online-users (atom {}))
 (defn- get-or-create-*online-users
   [graph-uuid]
-  (assert (uuid? graph-uuid))
+  (assert (uuid? graph-uuid) graph-uuid)
   (if-let [*online-users (get @*graph-uuid->*online-users graph-uuid)]
     *online-users
     (let [*online-users (atom nil)]

+ 23 - 22
src/main/frontend/worker/rtc/full_upload_download_graph.cljs

@@ -447,29 +447,30 @@
 
 (defn new-task--download-graph-from-s3
   [graph-uuid graph-name s3-url]
-  (m/sp
-    (rtc-log-and-state/rtc-log :rtc.log/download {:sub-type :downloading-graph-data
-                                                  :message "downloading graph data"
-                                                  :graph-uuid graph-uuid})
-    (let [{:keys [status body] :as r} (m/? (http/get s3-url {:with-credentials? false}))
-          repo                        (str sqlite-util/db-version-prefix graph-name)]
-      (if (not= 200 status)
-        (throw (ex-info "download-graph from s3 failed" {:resp r}))
-        (do
-          (rtc-log-and-state/rtc-log :rtc.log/download {:sub-type :transact-graph-data-to-db
-                                                        :message "transacting graph data to local db"
-                                                        :graph-uuid graph-uuid})
-          (let [all-blocks (ldb/read-transit-str body)]
-            (worker-state/set-rtc-downloading-graph! true)
-            (m/? (new-task--transact-remote-all-blocks! all-blocks repo graph-uuid))
-            (client-op/update-graph-uuid repo graph-uuid)
-            (when-not rtc-const/RTC-E2E-TEST
-              (c.m/<? (worker-db-metadata/<store repo (pr-str {:kv/value graph-uuid}))))
-            (worker-state/set-rtc-downloading-graph! false)
-            (rtc-log-and-state/rtc-log :rtc.log/download {:sub-type :download-completed
-                                                          :message "download completed"
+  (let [graph-uuid (if (string? graph-uuid) (parse-uuid graph-uuid) graph-uuid)]
+    (m/sp
+      (rtc-log-and-state/rtc-log :rtc.log/download {:sub-type :downloading-graph-data
+                                                    :message "downloading graph data"
+                                                    :graph-uuid graph-uuid})
+      (let [{:keys [status body] :as r} (m/? (http/get s3-url {:with-credentials? false}))
+            repo                        (str sqlite-util/db-version-prefix graph-name)]
+        (if (not= 200 status)
+          (throw (ex-info "download-graph from s3 failed" {:resp r}))
+          (do
+            (rtc-log-and-state/rtc-log :rtc.log/download {:sub-type :transact-graph-data-to-db
+                                                          :message "transacting graph data to local db"
                                                           :graph-uuid graph-uuid})
-            nil))))))
+            (let [all-blocks (ldb/read-transit-str body)]
+              (worker-state/set-rtc-downloading-graph! true)
+              (m/? (new-task--transact-remote-all-blocks! all-blocks repo graph-uuid))
+              (client-op/update-graph-uuid repo graph-uuid)
+              (when-not rtc-const/RTC-E2E-TEST
+                (c.m/<? (worker-db-metadata/<store repo (pr-str {:kv/value graph-uuid}))))
+              (worker-state/set-rtc-downloading-graph! false)
+              (rtc-log-and-state/rtc-log :rtc.log/download {:sub-type :download-completed
+                                                            :message "download completed"
+                                                            :graph-uuid graph-uuid})
+              nil)))))))
 
 (defn new-task--branch-graph
   [get-ws-create-task repo conn graph-uuid major-schema-version]