Просмотр исходного кода

enhance(perf): edit the page itself should be fast no matter how

many refs it has
Tienson Qin 4 лет назад
Родитель
Сommit
b46055328e
1 измененных файлов с 10 добавлено и 4 удалено
  1. 10 4
      src/main/frontend/db/react.cljs

+ 10 - 4
src/main/frontend/db/react.cljs

@@ -56,13 +56,19 @@
     (reset! query-state state)))
 
 (defn get-current-repo-refs-keys
-  []
+  [{:keys [key data]}]
   (when-let [current-repo (state/get-current-repo)]
     (->>
      (map (fn [[repo k id]]
             (when (and (= repo current-repo)
                        (contains? #{:block/refed-blocks :block/unlinked-refs} k))
-              [k id]))
+              (if (= k :block/refed-blocks)
+                (if (every? (fn [m]
+                              (when (map? m)
+                                (= id (:db/id (:block/page m))))) data)
+                  nil
+                  [k id])
+                [k id])))
        (keys @query-state))
      (remove nil?))))
 
@@ -250,7 +256,6 @@
 
                              (when current-page-id
                                [[:page/ref-pages current-page-id]
-                                ;; [:block/refed-blocks current-page-id]
                                 [:page/mentioned-pages current-page-id]])
 
                              (apply concat
@@ -272,7 +277,8 @@
                              (when (= k :block/refed-blocks)
                                [:page/ref-pages page-id]))
                             related-keys)
-              all-refed-blocks (get-current-repo-refs-keys)
+              all-refed-blocks (get-current-repo-refs-keys {:key key
+                                                            :data data})
               custom-queries (some->>
                               (filter (fn [v]
                                         (and (= (first v) (state/get-current-repo))