0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-27 23:21:47 -05:00

Merge pull request from penpot/alotor-performance-improvement

 Improved performance for root frame movement
This commit is contained in:
Aitor Moreno 2024-10-25 14:48:10 +02:00 committed by GitHub
commit 5718c1f287
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -308,6 +308,17 @@
(reduce calculate-modifiers [modif-tree bounds]) (reduce calculate-modifiers [modif-tree bounds])
(first)))) (first))))
(defn filter-layouts-ids
"Returns a list of ids without the root-frames with only move"
[objects modif-tree]
(->> modif-tree
(remove (fn [[id {:keys [modifiers]}]]
(or (ctm/empty? modifiers)
(and (cfh/root-frame? objects id)
(ctm/only-move? modifiers)))))
(map first)
(set)))
(defn set-objects-modifiers (defn set-objects-modifiers
"Applies recursively the modifiers and calculate the layouts and constraints for all the items to be placed correctly" "Applies recursively the modifiers and calculate the layouts and constraints for all the items to be placed correctly"
([modif-tree objects] ([modif-tree objects]
@ -331,9 +342,13 @@
(cgt/apply-structure-modifiers modif-tree)) (cgt/apply-structure-modifiers modif-tree))
;; Creates the sequence of shapes with the shapes that are modified ;; Creates the sequence of shapes with the shapes that are modified
shapes-tree shapes-tree-all
(cgst/resolve-tree (-> modif-tree keys set) objects) (cgst/resolve-tree (-> modif-tree keys set) objects)
;; This second sequence is used to recalculate layouts (we remove moved root-frames)
shapes-tree-layout
(cgst/resolve-tree (filter-layouts-ids objects modif-tree) objects)
bounds-map bounds-map
(cond-> (cgb/objects->bounds-map objects) (cond-> (cgb/objects->bounds-map objects)
(some? old-modif-tree) (some? old-modif-tree)
@ -347,13 +362,13 @@
;; Propagates the modifiers to the normal shapes with constraints ;; Propagates the modifiers to the normal shapes with constraints
modif-tree modif-tree
(propagate-modifiers-constraints objects bounds-map ignore-constraints modif-tree shapes-tree) (propagate-modifiers-constraints objects bounds-map ignore-constraints modif-tree shapes-tree-all)
bounds-map bounds-map
(cgb/transform-bounds-map bounds-map objects modif-tree) (cgb/transform-bounds-map bounds-map objects modif-tree)
modif-tree-layout modif-tree-layout
(propagate-modifiers-layouts objects bounds-map ignore-constraints shapes-tree) (propagate-modifiers-layouts objects bounds-map ignore-constraints shapes-tree-layout)
modif-tree modif-tree
(cgt/merge-modif-tree modif-tree modif-tree-layout) (cgt/merge-modif-tree modif-tree modif-tree-layout)
@ -363,7 +378,7 @@
(cgb/transform-bounds-map bounds-map objects modif-tree-layout) (cgb/transform-bounds-map bounds-map objects modif-tree-layout)
;; Find layouts with auto width/height ;; Find layouts with auto width/height
sizing-auto-layouts (find-auto-layouts objects shapes-tree) sizing-auto-layouts (find-auto-layouts objects shapes-tree-layout)
modif-tree modif-tree
(sizing-auto-modifiers modif-tree sizing-auto-layouts objects bounds-map ignore-constraints) (sizing-auto-modifiers modif-tree sizing-auto-layouts objects bounds-map ignore-constraints)