fix: more async queries and export to roam

This commit is contained in:
Tienson Qin
2024-01-30 20:03:06 +08:00
parent 96dcdd979a
commit 99b6d543f0
9 changed files with 45 additions and 33 deletions

View File

@@ -2,9 +2,9 @@
(:require [clojure.set :as s]
[clojure.string :as str]
[clojure.walk :as walk]
[datascript.core :as d]
[frontend.db :as db]
[frontend.state :as state]))
[frontend.db.async :as db-async]
[frontend.state :as state]
[promesa.core :as p]))
(def todo-marker-regex
#"^(NOW|LATER|TODO|DOING|WAITING|WAIT|CANCELED|CANCELLED|STARTED|IN-PROGRESS)")
@@ -20,18 +20,18 @@
(->> (repeatedly 9 nano-id-char)
(str/join)))
;; TODO: async
(defn uuid->uid-map []
(let [db (db/get-db (state/get-current-repo))]
(->>
(d/q '[:find (pull ?r [:block/uuid])
:in $
:where
[?b :block/refs ?r]] db)
(map (comp :block/uuid first))
(distinct)
(map (fn [uuid] [uuid (nano-id)]))
(into {}))))
(defn <uuid->uid-map []
(let [repo (state/get-current-repo)]
(p/let [result (db-async/<q repo
'[:find (pull ?r [:block/uuid])
:in $
:where
[?b :block/refs ?r]])]
(->> result
(map (comp :block/uuid first))
(distinct)
(map (fn [uuid] [uuid (nano-id)]))
(into {})))))
(defn update-content [content uuid->uid-map]
(when content ; page block doesn't have content
@@ -66,7 +66,7 @@
(defn traverse
[keyseq vec-tree]
(let [uuid->uid-map (uuid->uid-map)]
(p/let [uuid->uid-map (<uuid->uid-map)]
(walk/postwalk
(fn [x]
(cond