mirror of
https://github.com/penpot/penpot.git
synced 2025-05-25 21:46:12 +02:00
Merge pull request #6351 from penpot/niwinz-develop-improve-cleaner
✨ Add cleaner to file-gc
This commit is contained in:
commit
dbb9971482
3 changed files with 48 additions and 3 deletions
|
@ -9,6 +9,7 @@
|
||||||
for recently imported shapes."
|
for recently imported shapes."
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.types.shape :as cts]
|
||||||
[app.common.uuid :as uuid]))
|
[app.common.uuid :as uuid]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
@ -55,9 +56,52 @@
|
||||||
(fn [shadows]
|
(fn [shadows]
|
||||||
(into [] xform shadows)))))
|
(into [] xform shadows)))))
|
||||||
|
|
||||||
|
(defn- fix-root-shape
|
||||||
|
"Ensure all root objects are well formed shapes"
|
||||||
|
[shape]
|
||||||
|
(if (= (:id shape) uuid/zero)
|
||||||
|
(-> shape
|
||||||
|
(assoc :parent-id uuid/zero)
|
||||||
|
(assoc :frame-id uuid/zero)
|
||||||
|
;; We explicitly dissoc them and let the shape-setup
|
||||||
|
;; to regenerate it with valid values.
|
||||||
|
(dissoc :selrect)
|
||||||
|
(dissoc :points)
|
||||||
|
(cts/setup-shape))
|
||||||
|
shape))
|
||||||
|
|
||||||
|
(defn- fix-legacy-flex-dir
|
||||||
|
"This operation is only relevant to old data and it is fixed just
|
||||||
|
for convenience."
|
||||||
|
[shape]
|
||||||
|
(d/update-when shape :layout-flex-dir
|
||||||
|
(fn [dir]
|
||||||
|
(case dir
|
||||||
|
:reverse-row :row-reverse
|
||||||
|
:reverse-column :column-reverse
|
||||||
|
dir))))
|
||||||
|
|
||||||
(defn clean-shape-post-decode
|
(defn clean-shape-post-decode
|
||||||
"A shape procesor that expected to be executed after schema decoding
|
"A shape procesor that expected to be executed after schema decoding
|
||||||
process but before validation."
|
process but before validation."
|
||||||
[shape]
|
[shape]
|
||||||
(-> shape
|
(-> shape
|
||||||
(fix-shape-shadow-color)))
|
(fix-shape-shadow-color)
|
||||||
|
(fix-root-shape)
|
||||||
|
(fix-legacy-flex-dir)))
|
||||||
|
|
||||||
|
(defn- fix-container
|
||||||
|
[container]
|
||||||
|
(-> container
|
||||||
|
;; Remove possible `nil` keys on objects
|
||||||
|
(d/update-when :objects dissoc nil)
|
||||||
|
(d/update-when :objects d/update-vals clean-shape-post-decode)))
|
||||||
|
|
||||||
|
(defn clean-file
|
||||||
|
[file & {:as _opts}]
|
||||||
|
(update file :data
|
||||||
|
(fn [data]
|
||||||
|
(-> data
|
||||||
|
(d/update-when :pages-index d/update-vals fix-container)
|
||||||
|
(d/update-when :components d/update-vals fix-container)
|
||||||
|
(d/without-nils)))))
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
file is eligible to be garbage collected after some period of
|
file is eligible to be garbage collected after some period of
|
||||||
inactivity (the default threshold is 72h)."
|
inactivity (the default threshold is 72h)."
|
||||||
(:require
|
(:require
|
||||||
|
[app.binfile.cleaner :as bfl]
|
||||||
[app.binfile.common :as bfc]
|
[app.binfile.common :as bfc]
|
||||||
[app.common.files.helpers :as cfh]
|
[app.common.files.helpers :as cfh]
|
||||||
[app.common.files.validate :as cfv]
|
[app.common.files.validate :as cfv]
|
||||||
|
@ -258,6 +259,7 @@
|
||||||
(if-let [file (get-file cfg file-id)]
|
(if-let [file (get-file cfg file-id)]
|
||||||
(let [file (->> file
|
(let [file (->> file
|
||||||
(bfc/decode-file cfg)
|
(bfc/decode-file cfg)
|
||||||
|
(bfl/clean-file)
|
||||||
(clean-media! cfg)
|
(clean-media! cfg)
|
||||||
(clean-fragments! cfg))
|
(clean-fragments! cfg))
|
||||||
file (assoc file :has-media-trimmed true)]
|
file (assoc file :has-media-trimmed true)]
|
||||||
|
|
|
@ -58,8 +58,7 @@
|
||||||
[file-id revn]
|
[file-id revn]
|
||||||
(->> (wrk/ask! {:cmd :thumbnails/generate-for-file
|
(->> (wrk/ask! {:cmd :thumbnails/generate-for-file
|
||||||
:revn revn
|
:revn revn
|
||||||
:file-id file-id
|
:file-id file-id})
|
||||||
:features (get @st/state :features)})
|
|
||||||
(rx/mapcat (fn [{:keys [fonts] :as result}]
|
(rx/mapcat (fn [{:keys [fonts] :as result}]
|
||||||
(->> (fonts/render-font-styles fonts)
|
(->> (fonts/render-font-styles fonts)
|
||||||
(rx/map (fn [styles]
|
(rx/map (fn [styles]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue