Improved performance in workers

This commit is contained in:
alonso.torres 2021-01-27 15:59:55 +01:00
parent 385c7274a3
commit 44eb961c27
3 changed files with 24 additions and 14 deletions

View file

@ -108,7 +108,7 @@
(let [page-id (:current-page-id state)] (let [page-id (:current-page-id state)]
(rx/concat (rx/concat
(when (some :page-id changes) (when (some :page-id changes)
(rx/of (update-indices page-id))) (rx/of (update-indices page-id changes)))
(when (and save-undo? (seq undo-changes)) (when (and save-undo? (seq undo-changes))
(let [entry {:undo-changes undo-changes (let [entry {:undo-changes undo-changes
@ -174,14 +174,13 @@
(rx/map (constantly ::index-initialized))))))) (rx/map (constantly ::index-initialized)))))))
(defn update-indices (defn update-indices
[page-id] [page-id changes]
(ptk/reify ::update-indices (ptk/reify ::update-indices
ptk/EffectEvent ptk/EffectEvent
(effect [_ state stream] (effect [_ state stream]
(let [objects (lookup-page-objects state page-id)] (uw/ask! {:cmd :update-page-indices
(uw/ask! {:cmd :update-page-indices :page-id page-id
:page-id page-id :changes changes}))))
:objects objects})))))
;; --- Common Helpers & Events ;; --- Common Helpers & Events

View file

@ -206,7 +206,7 @@
(rx/merge (rx/merge
(rx/of (dwp/shapes-changes-persisted file-id msg)) (rx/of (dwp/shapes-changes-persisted file-id msg))
(when (seq page-ids) (when (seq page-ids)
(rx/from (map dwc/update-indices page-ids)))))))) (rx/from (map dwc/update-indices page-ids changes))))))))
(s/def ::library-change-event (s/def ::library-change-event
(s/keys :req-un [::type (s/keys :req-un [::type

View file

@ -7,10 +7,13 @@
(ns app.worker.impl (ns app.worker.impl
(:require (:require
[okulary.core :as l] [okulary.core :as l]
[app.util.transit :as t])) [app.util.transit :as t]
[app.common.pages.changes :as ch]))
(enable-console-print!) (enable-console-print!)
(defonce state (l/atom {:pages-index {}}))
;; --- Handler ;; --- Handler
(defmulti handler :cmd) (defmulti handler :cmd)
@ -24,15 +27,23 @@
message) message)
(defmethod handler :initialize-indices (defmethod handler :initialize-indices
[message] [{:keys [data] :as message}]
(reset! state data)
(handler (-> message (handler (-> message
(assoc :cmd :selection/initialize-index))) (assoc :cmd :selection/initialize-index)))
(handler (-> message (handler (-> message
(assoc :cmd :snaps/initialize-index)))) (assoc :cmd :snaps/initialize-index))))
(defmethod handler :update-page-indices (defmethod handler :update-page-indices
[message] [{:keys [page-id changes] :as message}]
(handler (-> message
(assoc :cmd :selection/update-index))) (swap! state ch/process-changes changes false)
(handler (-> message
(assoc :cmd :snaps/update-index)))) (let [objects (get-in @state [:pages-index page-id :objects])
message (assoc message :objects objects)]
(handler (-> message
(assoc :cmd :selection/update-index)))
(handler (-> message
(assoc :cmd :snaps/update-index)))))