0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 15:39:50 -05:00

Improved process-changes performance

This commit is contained in:
alonso.torres 2021-01-26 16:59:40 +01:00
parent cf77ebde6a
commit 815d1a906f
2 changed files with 17 additions and 9 deletions

View file

@ -29,12 +29,18 @@
(defmulti process-operation (fn [_ op] (:type op))) (defmulti process-operation (fn [_ op] (:type op)))
(defn process-changes (defn process-changes
[data items] ([data items] (process-changes data items true))
(->> (us/verify ::spec/changes items) ([data items verify?]
(reduce #(do ;; When verify? false we spec the schema validation. Currently used to make just
;; (prn "process-change" (:type %2) (:id %2)) ;; 1 validation even if the changes are applied twice
(or (process-change %1 %2) %1)) (when verify?
data))) (us/verify ::spec/changes items))
(reduce #(do
#_(prn "process-change" (:type %2) (:id %2))
(or (process-change %1 %2) %1))
data
items)))
(defmethod process-change :set-option (defmethod process-change :set-option
[data {:keys [page-id option value]}] [data {:keys [page-id option value]}]
@ -91,7 +97,7 @@
(let [update-fn (fn [objects] (let [update-fn (fn [objects]
(if-let [obj (get objects id)] (if-let [obj (get objects id)]
(let [result (reduce process-operation obj operations)] (let [result (reduce process-operation obj operations)]
(us/verify ::spec/shape result) #?(:clj (us/verify ::spec/shape result))
(assoc objects id result)) (assoc objects id result))
objects))] objects))]
(if page-id (if page-id

View file

@ -13,6 +13,7 @@
[app.common.geom.proportions :as gpr] [app.common.geom.proportions :as gpr]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.spec :as spec]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.worker :as uw] [app.main.worker :as uw]
@ -93,9 +94,10 @@
[:workspace-data] [:workspace-data]
[:workspace-libraries file-id :data])] [:workspace-libraries file-id :data])]
(try (try
(let [state (update-in state path1 cp/process-changes changes)] (us/verify ::spec/changes changes)
(let [state (update-in state path1 cp/process-changes changes false)]
(cond-> state (cond-> state
commit-local? (update-in path2 cp/process-changes changes))) commit-local? (update-in path2 cp/process-changes changes false)))
(catch :default e (catch :default e
(vreset! error e) (vreset! error e)
state)))) state))))