From 2befad433f0c5f4c5fd4668a83119314ef924dbd Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 11 Oct 2022 14:56:45 +0200 Subject: [PATCH] :zap: Remove unnecesary index building on :mov-objects --- common/src/app/common/pages/changes.cljc | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index 8f786a5b2..f7ccb2e6e 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -225,8 +225,8 @@ (-> (update :touched cph/set-touched-group :shapes-group) (dissoc :remote-synced?))))) - (remove-from-old-parent [cpindex objects shape-id] - (let [prev-parent-id (get cpindex shape-id)] + (remove-from-old-parent [old-objects objects shape-id] + (let [prev-parent-id (dm/get-in old-objects [shape-id :parent-id])] ;; Do nothing if the parent id of the shape is the same as ;; the new destination target parent id. (if (= prev-parent-id parent-id) @@ -263,17 +263,6 @@ (move-objects [objects] (let [valid? (every? (partial is-valid-move? objects) shapes) - - ;; Create a index of shape ids pointing to the - ;; corresponding parents; used mainly for update old - ;; parents after move operation. - cpindex (reduce (fn [index id] - (let [obj (get objects id)] - (assoc! index id (:parent-id obj)))) - (transient {}) - (keys objects)) - cpindex (persistent! cpindex) - parent (get objects parent-id) frame-id (if (= :frame (:type parent)) (:id parent) @@ -290,7 +279,7 @@ ;; Analyze the old parents and clear the old links ;; only if the new parent is different form old ;; parent. - (reduce (partial remove-from-old-parent cpindex) $ shapes) + (reduce (partial remove-from-old-parent objects) $ shapes) ;; Ensure that all shapes of the new parent has a ;; correct link to the topside frame.