From 12b1f3eaf33db0f8e8892e8ff86687ade7042329 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 21 Oct 2024 15:16:35 +0800 Subject: [PATCH] perf: reuse non-updated entities as possible as we can --- src/main/frontend/components/views.cljs | 10 +++++++--- src/main/frontend/modules/outliner/pipeline.cljs | 3 +++ src/main/frontend/state.cljs | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/frontend/components/views.cljs b/src/main/frontend/components/views.cljs index ee588899be6..913f3c306ec 100644 --- a/src/main/frontend/components/views.cljs +++ b/src/main/frontend/components/views.cljs @@ -6,6 +6,7 @@ [clojure.set :as set] [clojure.string :as string] [datascript.impl.entity :as de] + [datascript.core :as d] [frontend.components.dnd :as dnd] [frontend.components.property.value :as pv] [frontend.components.select :as select] @@ -28,9 +29,12 @@ (defn- get-latest-entity [e] - (assoc (db/entity (:db/id e)) - :id (:id e) - :block.temp/refs-count (:block.temp/refs-count e))) + (let [transacted-ids (:updated-ids @(:db/latest-transacted-entity-uuids @state/state))] + (if (and transacted-ids (contains? transacted-ids (:block/uuid e))) + (assoc (db/entity (:db/id e)) + :id (:id e) + :block.temp/refs-count (:block.temp/refs-count e)) + e))) (rum/defc header-checkbox < rum/static [{:keys [selected-all? selected-some? toggle-selected-all!]}] diff --git a/src/main/frontend/modules/outliner/pipeline.cljs b/src/main/frontend/modules/outliner/pipeline.cljs index 868d59b55ca..050ae3f7132 100644 --- a/src/main/frontend/modules/outliner/pipeline.cljs +++ b/src/main/frontend/modules/outliner/pipeline.cljs @@ -35,6 +35,9 @@ :else (do + (state/set-state! :db/latest-updated-entity-uuids + {:updated-ids (set (map :block/uuid blocks)) + :deleted-ids (set deleted-block-uuids)}) (let [tx-data' (concat (map (fn [id] diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 4026988237f..d0d26d48047 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -319,7 +319,8 @@ :ui/select-query-cache (atom {}) :favorites/updated? (atom 0) :db/async-query-loading (atom #{}) - :db/async-queries (atom {})}))) + :db/async-queries (atom {}) + :db/latest-transacted-entity-uuids (atom {})}))) ;; Block ast state ;; ===============