mirror of
https://github.com/penpot/penpot.git
synced 2025-07-07 19:17:17 +02:00
⚡ Improves boolean performance
This commit is contained in:
parent
b2211aec59
commit
99a6142134
8 changed files with 271 additions and 120 deletions
|
@ -28,6 +28,7 @@
|
|||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.common :as dwc]
|
||||
[app.main.data.workspace.drawing :as dwd]
|
||||
[app.main.data.workspace.fix-bool-contents :as fbc]
|
||||
[app.main.data.workspace.groups :as dwg]
|
||||
[app.main.data.workspace.interactions :as dwi]
|
||||
[app.main.data.workspace.libraries :as dwl]
|
||||
|
@ -213,8 +214,11 @@
|
|||
(or (not ignore-until)
|
||||
(> (:modified-at %) ignore-until)))
|
||||
libraries)]
|
||||
(when needs-update?
|
||||
(rx/of (dwl/notify-sync-file file-id)))))))
|
||||
(rx/merge
|
||||
(rx/of (fbc/fix-bool-contents))
|
||||
(if needs-update?
|
||||
(rx/of (dwl/notify-sync-file file-id))
|
||||
(rx/empty)))))))
|
||||
|
||||
(defn finalize-file
|
||||
[_project-id file-id]
|
||||
|
@ -307,7 +311,7 @@
|
|||
[page-id]
|
||||
(ptk/reify ::duplicate-page
|
||||
ptk/WatchEvent
|
||||
(watch [this state _]
|
||||
(watch [it state _]
|
||||
(let [id (uuid/next)
|
||||
pages (get-in state [:workspace-data :pages-index])
|
||||
unames (dwc/retrieve-used-names pages)
|
||||
|
@ -322,7 +326,7 @@
|
|||
:id id}]
|
||||
(rx/of (dch/commit-changes {:redo-changes [rchange]
|
||||
:undo-changes [uchange]
|
||||
:origin this}))))))
|
||||
:origin it}))))))
|
||||
|
||||
(s/def ::rename-page
|
||||
(s/keys :req-un [::id ::name]))
|
||||
|
|
94
frontend/src/app/main/data/workspace/fix_bool_contents.cljs
Normal file
94
frontend/src/app/main/data/workspace/fix_bool_contents.cljs
Normal file
|
@ -0,0 +1,94 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) UXBOX Labs SL
|
||||
|
||||
(ns app.main.data.workspace.fix-bool-contents
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.main.data.workspace.changes :as dch]
|
||||
[app.main.data.workspace.state-helpers :as wsh]
|
||||
[beicon.core :as rx]
|
||||
[potok.core :as ptk]))
|
||||
|
||||
;; This event will update the file so the boolean data has a pre-generated path data
|
||||
;; to increase performance.
|
||||
;; For new shapes this will be generated in the :reg-objects but we need to do this for
|
||||
;; old files.
|
||||
|
||||
;; FIXME: Remove me after June 2022
|
||||
|
||||
(defn fix-bool-contents
|
||||
"This event will calculate the bool content and update the page. This is kind of a 'addhoc' migration
|
||||
to fill the optional value 'bool-content'"
|
||||
[]
|
||||
|
||||
(letfn [(should-migrate-shape? [shape]
|
||||
(and (= :bool (:type shape)) (not (contains? shape :bool-content))))
|
||||
|
||||
(should-migrate-component? [component]
|
||||
(->> (:objects component)
|
||||
(vals)
|
||||
(d/seek should-migrate-shape?)))
|
||||
|
||||
(update-shape [shape objects]
|
||||
(cond-> shape
|
||||
(should-migrate-shape? shape)
|
||||
(assoc :bool-content (gsh/calc-bool-content shape objects))))
|
||||
|
||||
(migrate-component [component]
|
||||
(-> component
|
||||
(update
|
||||
:objects
|
||||
(fn [objects]
|
||||
(d/mapm #(update-shape %2 objects) objects)))))
|
||||
|
||||
(update-library
|
||||
[library]
|
||||
(-> library
|
||||
(d/update-in-when
|
||||
[:data :components]
|
||||
(fn [components]
|
||||
(d/mapm #(migrate-component %2) components)))))]
|
||||
|
||||
(ptk/reify ::fix-bool-contents
|
||||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
;; Update (only-local) the imported libraries
|
||||
(-> state
|
||||
(d/update-when
|
||||
:workspace-libraries
|
||||
(fn [libraries] (d/mapm #(update-library %2) libraries)))))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [objects (wsh/lookup-page-objects state)
|
||||
|
||||
ids (into #{}
|
||||
(comp (filter should-migrate-shape?) (map :id))
|
||||
(vals objects))
|
||||
|
||||
components (->> (wsh/lookup-local-components state)
|
||||
(vals)
|
||||
(filter should-migrate-component?))
|
||||
|
||||
component-changes
|
||||
(into []
|
||||
(map (fn [component]
|
||||
{:type :mod-component
|
||||
:id (:id component)
|
||||
:objects (-> component migrate-component :objects)}))
|
||||
components)]
|
||||
|
||||
(rx/of (dch/update-shapes ids #(update-shape % objects) {:reg-objects? false
|
||||
:save-undo? false
|
||||
:ignore-tree true}))
|
||||
|
||||
(if (empty? component-changes)
|
||||
(rx/empty)
|
||||
(rx/of (dch/commit-changes {:origin it
|
||||
:redo-changes component-changes
|
||||
:undo-changes []
|
||||
:save-undo? false}))))))))
|
|
@ -25,6 +25,10 @@
|
|||
([state component-id]
|
||||
(get-in state [:workspace-data :components component-id :objects])))
|
||||
|
||||
(defn lookup-local-components
|
||||
([state]
|
||||
(get-in state [:workspace-data :components])))
|
||||
|
||||
(defn lookup-selected
|
||||
([state]
|
||||
(lookup-selected state nil))
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
(ns app.main.ui.shapes.bool
|
||||
(:require
|
||||
[app.common.path.bool :as pb]
|
||||
[app.common.path.shapes-to-path :as stp]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.main.ui.hooks :refer [use-equal-memo]]
|
||||
[app.main.ui.shapes.export :as use]
|
||||
[app.main.ui.shapes.path :refer [path-shape]]
|
||||
|
@ -27,13 +26,8 @@
|
|||
bool-content
|
||||
(mf/use-memo
|
||||
(mf/deps shape childs)
|
||||
(fn []
|
||||
(->> (:shapes shape)
|
||||
(map #(get childs %))
|
||||
(filter #(not (:hidden %)))
|
||||
(map #(stp/convert-to-path % childs))
|
||||
(mapv :content)
|
||||
(pb/content-bool (:bool-type shape)))))]
|
||||
#(or (:bool-content shape)
|
||||
(gsh/calc-bool-content shape childs)))]
|
||||
|
||||
[:*
|
||||
[:& path-shape {:shape (assoc shape :content bool-content)}]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue