Skip to content

Commit

Permalink
perf: reuse non-updated entities as possible as we can
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Oct 21, 2024
1 parent 65c16a4 commit 12b1f3e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/main/frontend/components/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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!]}]
Expand Down
3 changes: 3 additions & 0 deletions src/main/frontend/modules/outliner/pipeline.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion src/main/frontend/state.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
;; ===============
Expand Down

0 comments on commit 12b1f3e

Please sign in to comment.