Procházet zdrojové kódy

fix: don't depend frontend.(db|state) in worker ns

Tienson Qin před 1 rokem
rodič
revize
75463c4df4

+ 7 - 1
deps/common/src/logseq/common/util.cljs

@@ -8,7 +8,8 @@
             [logseq.common.log :as log]
             [goog.string :as gstring]
             [cljs-time.coerce :as tc]
-            [cljs-time.core :as t]))
+            [cljs-time.core :as t]
+            [datascript.core :as d]))
 
 (defn safe-decode-uri-component
   [uri]
@@ -347,3 +348,8 @@ return: [{:id 3} {:id 2 :depend-on 3} {:id 1 :depend-on 2}]"
                 (vreset! seen-ids #{})
                 (recur (conj r id) rest-ids* (first rest-ids*))))))]
     (mapv id->elem sorted-ids)))
+
+(defn db-based-graph?
+  "Whether the current graph is db-only"
+  [db]
+  (= "db" (:kv/value (d/entity db :logseq.kv/db-type))))

+ 2 - 3
deps/db/src/logseq/db/frontend/content.cljs

@@ -3,7 +3,6 @@
   (:require [clojure.string :as string]
             [logseq.common.util.page-ref :as page-ref]
             [datascript.core :as d]
-            [logseq.db.sqlite.util :as sqlite-util]
             [logseq.common.util :as common-util]))
 
 (defonce page-ref-special-chars "~^")
@@ -95,8 +94,8 @@
 
 (defn update-block-content
   "Replace `[[internal-id]]` with `[[page name]]`"
-  [repo db item eid]
-  (if (sqlite-util/db-based-graph? repo)
+  [db item eid]
+  (if (common-util/db-based-graph? db)
     (if-let [content (:block/title item)]
       (let [refs (:block/refs (d/entity db eid))]
         (assoc item :block/title (special-id-ref->page-ref content refs)))

+ 3 - 6
deps/db/src/logseq/db/frontend/entity_plus.cljc

@@ -9,13 +9,10 @@
             #?(:org.babashka/nbb [datascript.db])
             [datascript.impl.entity :as entity :refer [Entity]]
             [logseq.db.frontend.content :as db-content]
-            [datascript.core :as d]
-            [logseq.db.frontend.property :as db-property]))
+            [logseq.db.frontend.property :as db-property]
+            [logseq.common.util :as common-util]))
 
-(defn db-based-graph?
-  "Whether the current graph is db-only"
-  [db]
-  (= "db" (:kv/value (d/entity db :logseq.kv/db-type))))
+(def db-based-graph? common-util/db-based-graph?)
 
 (def lookup-entity @#'entity/lookup-entity)
 (defn lookup-kv-then-entity

+ 2 - 3
src/main/frontend/db/utils.cljs

@@ -45,9 +45,8 @@
 (defn update-block-content
   "Replace `[[internal-id]]` with `[[page name]]`"
   [item eid]
-  (let [repo (state/get-current-repo)
-        db (conn/get-db repo)]
-    (db-content/update-block-content repo db item eid)))
+  (let [db (conn/get-db)]
+    (db-content/update-block-content db item eid)))
 
 (defn pull
   ([eid]

+ 4 - 3
src/main/frontend/worker/export.cljs

@@ -1,11 +1,11 @@
 (ns frontend.worker.export
   "Export data"
   (:require [datascript.core :as d]
-            [frontend.db :as db]
             [frontend.worker.file.core :as worker-file]
             [logseq.db :as ldb]
             [logseq.graph-parser.property :as gp-property]
-            [logseq.outliner.tree :as otree]))
+            [logseq.outliner.tree :as otree]
+            [logseq.db.frontend.content :as db-content]))
 
 (defn block->content
   "Converts a block including its children (recursively) to plain-text."
@@ -15,7 +15,8 @@
                        (if (ldb/page? (d/entity db [:block/uuid root-block-uuid]))
                          0
                          1))
-        blocks (db/pull-many (keep :db/id (ldb/get-block-and-children db root-block-uuid)))
+        blocks (->> (ldb/get-block-and-children db root-block-uuid)
+                    (map #(db-content/update-block-content db % (:db/id %))))
         tree (otree/blocks->vec-tree repo db blocks (str root-block-uuid))]
     (worker-file/tree->file-content repo db tree
                                     (assoc tree->file-opts :init-level init-level)