|
|
@@ -2250,31 +2250,21 @@
|
|
|
[?h :block/collapsed? true]]
|
|
|
(get-conn)))
|
|
|
|
|
|
-;; recursive query might be slow, need benchmarks
|
|
|
-;; Could replace this with a recursive call or , see below
|
|
|
-(defn get-block-parents-rec
|
|
|
- [repo block-id depth]
|
|
|
- (when-let [conn (get-conn repo)]
|
|
|
- (let [ids (->> (d/q
|
|
|
- '[:find ?e2
|
|
|
- :in $ ?e1 %
|
|
|
- :where (parent ?e2 ?e1)]
|
|
|
- conn
|
|
|
- block-id
|
|
|
- ;; recursive rules
|
|
|
- '[[(parent ?e2 ?e1)
|
|
|
- [?e2 :block/children ?e1]]
|
|
|
- [(parent ?e2 ?e1)
|
|
|
- [?t :block/children ?e1]
|
|
|
- (parent ?e2 ?t)]])
|
|
|
- (seq-flatten))]
|
|
|
- (when (seq ids)
|
|
|
- (pull-many repo '[:block/uuid :block/title] ids)))))
|
|
|
-
|
|
|
(defn get-block-parent
|
|
|
[repo block-id]
|
|
|
(when-let [conn (get-conn repo)]
|
|
|
- (d/entity conn [:block/children [:block/uuid block-id]])))
|
|
|
+ (when-let [id (:db/id (d/entity conn [:block/uuid block-id]))]
|
|
|
+ (d/entity conn [:block/children id]))))
|
|
|
+
|
|
|
+;; Using reverse lookup, a bit slow compared to get-block-parents
|
|
|
+#_(defn get-block-parents-rec
|
|
|
+ [repo block-id depth]
|
|
|
+ (when-let [conn (get-conn repo)]
|
|
|
+ (let [id (:db/id (entity repo [:block/uuid block-id]))]
|
|
|
+ (d/pull conn
|
|
|
+ '[:db/id :block/uuid :block/title :block/content
|
|
|
+ {:block/_children ...}]
|
|
|
+ id))))
|
|
|
|
|
|
;; non recursive query
|
|
|
(defn get-block-parents
|
|
|
@@ -2418,6 +2408,7 @@
|
|
|
last-level 10000]
|
|
|
(if (seq blocks)
|
|
|
(let [[{:block/keys [uuid level] :as block} & others] blocks
|
|
|
+ db-id (:db/id block)
|
|
|
[tx children] (cond
|
|
|
(< level last-level) ; parent
|
|
|
(let [cur-children (get children last-level)
|
|
|
@@ -2427,20 +2418,20 @@
|
|
|
tx
|
|
|
(map
|
|
|
(fn [child]
|
|
|
- [:db/add (:db/id block) :block/children [:block/uuid child]])
|
|
|
+ [:db/add (:db/id block) :block/children child])
|
|
|
cur-children)))
|
|
|
tx)
|
|
|
children (-> children
|
|
|
(dissoc last-level)
|
|
|
- (update level conj uuid))]
|
|
|
+ (update level conj db-id))]
|
|
|
[tx children])
|
|
|
|
|
|
(> level last-level) ; child of sibling
|
|
|
- (let [children (update children level conj uuid)]
|
|
|
+ (let [children (update children level conj db-id)]
|
|
|
[tx children])
|
|
|
|
|
|
:else ; sibling
|
|
|
- (let [children (update children last-level conj uuid)]
|
|
|
+ (let [children (update children last-level conj db-id)]
|
|
|
[tx children]))]
|
|
|
(recur others tx children level))
|
|
|
;; TODO: add top-level children to the "Page" block (we might remove the Page from db schema)
|