Browse Source

chore: cleanup :block/_left usage

Tienson Qin 1 year ago
parent
commit
5013d34c2f

+ 6 - 6
deps/db/src/logseq/db.cljs

@@ -222,7 +222,11 @@
                   (get-first-page-by-name db page-id)
                   page-id)
         page (d/entity db page-id)]
-    (nil? (:block/_left page))))
+    (empty? (:block/_parent page))))
+
+(defn get-first-child
+  [db id]
+  (first (sort-by-order (:block/_parent (d/entity db id)))))
 
 (defn get-orphaned-pages
   [db {:keys [pages empty-ref-f built-in-pages-names]
@@ -240,7 +244,7 @@
                                 (empty-ref-f page)
                                 (or
                                  (page-empty? db (:db/id page))
-                                 (let [first-child (first (:block/_left page))
+                                 (let [first-child (get-first-child db (:db/id page))
                                        children (:block/_page page)]
                                    (and
                                     first-child
@@ -308,10 +312,6 @@
 (def get-block-children-ids sqlite-common-db/get-block-children-ids)
 (def get-block-children sqlite-common-db/get-block-children)
 
-(defn get-first-child
-  [db id]
-  (first (sort-by-order (:block/_parent (d/entity db id)))))
-
 (defn- get-sorted-page-block-ids
   [db page-id]
   (let [root (d/entity db page-id)]

+ 2 - 2
src/main/frontend/handler/common/page.cljs

@@ -44,7 +44,7 @@
          [_ page-name page-uuid] (worker-page/create! repo conn config title options)]
      (when redirect?
        (route-handler/redirect-to-page! page-uuid))
-     (when-let [first-block (first (:block/_left (db/get-page page-uuid)))]
+     (when-let [first-block (ldb/get-first-child (db/get-db) (:db/id (db/get-page page-uuid)))]
        (block-handler/edit-block! first-block :max {:container-id :unknown-container}))
      page-name)))
 
@@ -62,7 +62,7 @@
      (when redirect?
        (route-handler/redirect-to-page! page-uuid))
      (let [page (db/get-page page-uuid)]
-       (when-let [first-block (first (:block/_left page))]
+       (when-let [first-block (ldb/get-first-child @conn (:db/id page))]
          (block-handler/edit-block! first-block :max {:container-id :unknown-container}))
        page))))
 

+ 1 - 9
src/main/frontend/worker/search.cljs

@@ -188,14 +188,6 @@
   (when (contains? (:block/type ent) "closed value")
     (:block/content ent)))
 
-(defn get-by-parent-&-left
-  [db parent-id left-id]
-  (when (and parent-id left-id)
-    (let [lefts (:block/_left (d/entity db left-id))]
-      (some (fn [node] (when (and (= parent-id (:db/id (:block/parent node)))
-                                  (not= parent-id (:db/id node)))
-                         node)) lefts))))
-
 (defn- get-db-properties-str
   "Similar to db-pu/readable-properties but with a focus on making property values searchable"
   [db properties]
@@ -219,7 +211,7 @@
                                             (:block/content e))
                                            ;; first child
                                            (let [parent-id (:db/id e)]
-                                             (:block/content (get-by-parent-&-left db parent-id parent-id))))]
+                                             (:block/content (ldb/get-first-child db parent-id))))]
                                 value)
                               val)))
                      (remove string/blank?))]