Skip to content

Commit b4f3e36

Browse files
fix: duplication of exporter config leads to bugs
in script and test. Also fix <export-file not being waited on and new docs after #12260
1 parent bcad782 commit b4f3e36

4 files changed

Lines changed: 33 additions & 28 deletions

File tree

deps/graph-parser/script/db_import.cljs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@
111111
;; :set-ui-state prn
112112
;; config file options
113113
;; TODO: Add actual default
114-
:default-config {}})
114+
:default-config {}
115+
;; TODO: Add zotero support
116+
;; :<get-file-stat (fn [path])
117+
})
115118

116119
(defn- import-file-graph-to-db
117120
"Import a file graph dir just like UI does. However, unlike the UI the

deps/graph-parser/src/logseq/graph_parser/exporter.cljs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,13 +1208,13 @@
12081208

12091209
(defn- <handle-assets-in-block
12101210
"If a block contains assets, creates them as #Asset nodes in the Asset page and references them in the block."
1211-
[config block {:keys [asset-links]} {:keys [assets ignored-assets pdf-annotation-pages]} {:keys [notify-user <get-file-stat] :as opts}]
1211+
[block {:keys [asset-links]} {:keys [assets ignored-assets pdf-annotation-pages]} {:keys [notify-user <get-file-stat user-config] :as opts}]
12121212
(if (seq asset-links)
12131213
(p/let [asset-maps* (p/all (map
12141214
(fn [asset-link]
12151215
(p/let [path* (-> asset-link second :url second)
12161216
{:keys [path link base]} (if (map? path*)
1217-
(get-zotero-local-pdf-path config (second asset-link))
1217+
(get-zotero-local-pdf-path user-config (second asset-link))
12181218
{:path path*})
12191219
asset-name (-> path asset-path->name)
12201220
asset-link-or-name (or link (-> path asset-path->name))
@@ -1313,16 +1313,17 @@
13131313
block))
13141314

13151315
(defn- <build-block-tx
1316-
[db config block* pre-blocks {:keys [page-names-to-uuids] :as per-file-state} {:keys [import-state journal-created-ats] :as options}]
1316+
[db block* pre-blocks {:keys [page-names-to-uuids] :as per-file-state}
1317+
{:keys [import-state journal-created-ats user-config] :as options}]
13171318
;; (prn ::block-in block*)
1318-
(p/let [walked-ast-blocks (walk-ast-blocks config (:block.temp/ast-blocks block*))
1319+
(p/let [walked-ast-blocks (walk-ast-blocks user-config (:block.temp/ast-blocks block*))
13191320
;; needs to come before update-block-refs to detect new property schemas
13201321
{:keys [block properties-tx]}
13211322
(handle-block-properties block* db page-names-to-uuids (:block/refs block*) walked-ast-blocks options)
13221323
{block-after-built-in-props :block deadline-properties-tx :properties-tx}
13231324
(update-block-deadline-and-scheduled block page-names-to-uuids options)
13241325
{block-after-assets :block :keys [asset-blocks-tx]}
1325-
(<handle-assets-in-block config block-after-built-in-props walked-ast-blocks import-state (select-keys options [:log-fn :notify-user :<get-file-stat]))
1326+
(<handle-assets-in-block block-after-built-in-props walked-ast-blocks import-state (select-keys options [:log-fn :notify-user :<get-file-stat]))
13261327
;; :block/page should be [:block/page NAME]
13271328

13281329
journal-page-created-at (some-> (:block/page block*) second journal-created-ats)
@@ -1811,11 +1812,11 @@
18111812
(swap! (:all-existing-page-uuids import-state) merge (into {} (map (juxt :block/uuid identity) nodes)))))
18121813

18131814
(defn- <build-blocks-tx
1814-
[conn config blocks pre-blocks per-file-state tx-options]
1815+
[conn blocks pre-blocks per-file-state tx-options]
18151816
(p/loop [tx-data []
18161817
blocks (remove :block/pre-block? blocks)]
18171818
(if-let [block (first blocks)]
1818-
(p/let [block-tx-data (<build-block-tx @conn config block pre-blocks per-file-state
1819+
(p/let [block-tx-data (<build-block-tx @conn block pre-blocks per-file-state
18191820
tx-options)]
18201821
(p/recur (concat tx-data block-tx-data) (rest blocks)))
18211822
tx-data)))
@@ -1831,10 +1832,10 @@
18311832
* :macros - map of macros for use with macro expansion
18321833
* :notify-user - Displays warnings to user without failing the import. Fn receives a map with :msg
18331834
* :log-fn - Logs messages for development. Defaults to prn"
1834-
[conn config file content {:keys [notify-user log-fn]
1835-
:or {notify-user #(println "[WARNING]" (:msg %))
1836-
log-fn prn}
1837-
:as *options}]
1835+
[conn file content {:keys [notify-user log-fn]
1836+
:or {notify-user #(println "[WARNING]" (:msg %))
1837+
log-fn prn}
1838+
:as *options}]
18381839
(p/let [options (assoc *options :notify-user notify-user :log-fn log-fn :file file)
18391840
{:keys [pages blocks]} (extract-pages-and-blocks @conn file content options)
18401841
tx-options (merge (build-tx-options options)
@@ -1851,7 +1852,7 @@
18511852
pre-blocks (->> blocks (keep #(when (:block/pre-block? %) (:block/uuid %))) set)
18521853

18531854
blocks-tx (let [tx-options' (assoc tx-options :whiteboard? (some? (seq whiteboard-pages)))]
1854-
(<build-blocks-tx conn config blocks pre-blocks per-file-state tx-options'))
1855+
(<build-blocks-tx conn blocks pre-blocks per-file-state tx-options'))
18551856
{:keys [property-pages-tx property-page-properties-tx] pages-tx' :pages-tx}
18561857
(split-pages-and-properties-tx pages-tx old-properties existing-pages (:import-state options) @(:upstream-properties tx-options))
18571858
;; _ (when (seq property-pages-tx) (cljs.pprint/pprint {:property-pages-tx property-pages-tx}))
@@ -1898,18 +1899,18 @@
18981899
;; =======================
18991900

19001901
(defn- export-doc-file
1901-
[{:keys [path idx] :as file} conn config <read-file
1902+
[{:keys [path idx] :as file} conn <read-file
19021903
{:keys [notify-user set-ui-state <export-file]
19031904
:or {set-ui-state (constantly nil)
1904-
<export-file (fn <export-file [conn config m opts]
1905-
(<add-file-to-db-graph conn config (:file/path m) (:file/content m) opts))}
1905+
<export-file (fn <export-file [conn m opts]
1906+
(<add-file-to-db-graph conn (:file/path m) (:file/content m) opts))}
19061907
:as options}]
19071908
;; (prn :export-doc-file path idx)
19081909
(-> (p/let [_ (set-ui-state [:graph/importing-state :current-idx] (inc idx))
19091910
_ (set-ui-state [:graph/importing-state :current-page] path)
19101911
content (<read-file file)
1911-
m {:file/path path :file/content content}]
1912-
(<export-file conn config m (dissoc options :set-ui-state :<export-file))
1912+
m {:file/path path :file/content content}
1913+
_ (<export-file conn m (dissoc options :set-ui-state :<export-file))]
19131914
;; returning val results in smoother ui updates
19141915
m)
19151916
(p/catch (fn [error]
@@ -1920,9 +1921,9 @@
19201921
(defn export-doc-files
19211922
"Exports all user created files i.e. under journals/ and pages/.
19221923
Recommended to use build-doc-options and pass that as options"
1923-
[conn config *doc-files <read-file {:keys [notify-user set-ui-state]
1924-
:or {set-ui-state (constantly nil) notify-user prn}
1925-
:as options}]
1924+
[conn *doc-files <read-file {:keys [notify-user set-ui-state]
1925+
:or {set-ui-state (constantly nil) notify-user prn}
1926+
:as options}]
19261927
(set-ui-state [:graph/importing-state :total] (count *doc-files))
19271928
(let [doc-files (mapv #(assoc %1 :idx %2)
19281929
;; Sort files to ensure reproducible import behavior
@@ -1931,10 +1932,10 @@
19311932
[(not (string/starts-with? (node-path/basename path) "hls__")) path])
19321933
*doc-files)
19331934
(range 0 (count *doc-files)))]
1934-
(-> (p/loop [_file-map (export-doc-file (get doc-files 0) conn config <read-file options)
1935+
(-> (p/loop [_file-map (export-doc-file (get doc-files 0) conn <read-file options)
19351936
i 0]
19361937
(when-not (>= i (dec (count doc-files)))
1937-
(p/recur (export-doc-file (get doc-files (inc i)) conn config <read-file options)
1938+
(p/recur (export-doc-file (get doc-files (inc i)) conn <read-file options)
19381939
(inc i))))
19391940
(p/catch (fn [e]
19401941
(notify-user {:msg (str "Import has unexpected error:\n" (.-message e))
@@ -2139,8 +2140,9 @@
21392140
* :log-fn - fn which logs developer messages
21402141
* :rpath-key - keyword used to get relative path in file map. Default to :path
21412142
* :<read-file - fn which reads a file across multiple steps
2143+
* :<get-file-stat - fn which returns stat of a file path
21422144
* :default-config - default config if config is unable to be read
2143-
* :user-options - map of user specific options. See add-file-to-db-graph for more
2145+
* :user-options - map of user specific options. See <add-file-to-db-graph for more
21442146
* :<save-config-file - fn which saves a config file
21452147
* :<save-logseq-file - fn which saves a logseq file
21462148
* :<read-and-copy-asset - fn which reads and copies asset file
@@ -2174,7 +2176,7 @@
21742176
<read-and-copy-asset
21752177
(merge (select-keys options [:notify-user :set-ui-state :rpath-key])
21762178
{:assets (get-in doc-options [:import-state :assets])}))
2177-
(export-doc-files conn config doc-files <read-file doc-options)
2179+
(export-doc-files conn doc-files <read-file doc-options)
21782180
(export-favorites-from-config-edn conn repo-or-conn config {})
21792181
(export-class-properties conn repo-or-conn)
21802182
(move-top-parent-pages-to-library conn repo-or-conn)

deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
(dissoc options :user-config :verbose))}
142142
(select-keys options [:verbose])))
143143
files' (mapv #(hash-map :path %) files)
144-
_ (gp-exporter/export-doc-files conn {} files' <read-file doc-options)]
144+
_ (gp-exporter/export-doc-files conn files' <read-file doc-options)]
145145
{:import-state (:import-state doc-options)})
146146
(p/finally (fn [_]
147147
(reset! gp-block/*export-to-db-graph? false)))))

src/main/frontend/components/imports.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@
412412
:<read-and-copy-asset #(read-and-copy-asset repo (config/get-repo-dir repo) %1 %2 %3)
413413
;; doc file options
414414
;; Write to frontend first as writing to worker first is poor ux with slow streaming changes
415-
:<export-file (fn <export-file [conn config m opts]
415+
:<export-file (fn <export-file [conn m opts]
416416
(p/let [tx-reports
417-
(gp-exporter/<add-file-to-db-graph conn config (:file/path m) (:file/content m) opts)]
417+
(gp-exporter/<add-file-to-db-graph conn (:file/path m) (:file/content m) opts)]
418418
(doseq [tx-report tx-reports]
419419
(db-browser/transact! repo (:tx-data tx-report) (:tx-meta tx-report)))))}
420420
{:keys [files import-state]} (gp-exporter/export-file-graph repo db-conn config-file *files options)]

0 commit comments

Comments
 (0)