Browse Source

perf: remove block-has-children? function

Tienson Qin 5 years ago
parent
commit
1b34099928
2 changed files with 2 additions and 9 deletions
  1. 1 7
      src/main/frontend/db.cljs
  2. 1 2
      src/main/frontend/handler/editor.cljs

+ 1 - 7
src/main/frontend/db.cljs

@@ -1218,6 +1218,7 @@
                   [(?pred $ ?meta)]])
              react))))
 
+;; TODO: performance
 (defn get-block-and-children-no-cache
   [repo block-uuid]
   (let [block (entity repo [:block/uuid block-uuid])
@@ -1238,13 +1239,6 @@
          pred)
         (block-and-children-transform repo block-uuid level))))
 
-(defn block-has-children?
-  [repo block]
-  (let [blocks (get-block-and-children-no-cache repo (:block/uuid block))
-        second-block (second blocks)]
-    (and second-block
-         (> (:block/level second-block) (:block/level block)))))
-
 (defn get-file-page
   ([file-path]
    (get-file-page file-path true))

+ 1 - 2
src/main/frontend/handler/editor.cljs

@@ -571,8 +571,7 @@
               (dec (count value))
               (util/get-input-pos input))
         repo (or repo (state/get-current-repo))
-        ;; block-has-children? (seq children) ; not working for now
-        block-has-children? (db/block-has-children? repo block)
+        block-has-children? (seq (:block/children block))
         fst-block-text (subs value 0 pos)
         snd-block-text (string/triml (subs value pos))
         fst-block-text (string/trim (if with-level? fst-block-text (block/with-levels fst-block-text format block)))