0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -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)))
(defn process-changes
[data items]
(->> (us/verify ::spec/changes items)
(reduce #(do
;; (prn "process-change" (:type %2) (:id %2))
(or (process-change %1 %2) %1))
data)))
([data items] (process-changes data items true))
([data items verify?]
;; When verify? false we spec the schema validation. Currently used to make just
;; 1 validation even if the changes are applied twice
(when verify?
(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
[data {:keys [page-id option value]}]
@ -91,7 +97,7 @@
(let [update-fn (fn [objects]
(if-let [obj (get objects id)]
(let [result (reduce process-operation obj operations)]
(us/verify ::spec/shape result)
#?(:clj (us/verify ::spec/shape result))
(assoc objects id result))
objects))]
(if page-id

View file

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