0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 00:58:26 -05:00

Merge pull request #1940 from penpot/repair-idless-components

🔧 Add a function to manually repair components without :id
This commit is contained in:
Alejandro 2022-05-25 09:04:19 +02:00 committed by GitHub
commit 38bc3b061a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -99,6 +99,27 @@
(update data :pages-index d/update-vals update-page)))
(defn repair-idless-components
"There are some files that contains components with no :id attribute.
This function detects them and repairs it.
Use it with the update-file function above."
[data]
(letfn [(update-component [id component]
(if (nil? (:id component))
(do
(prn (:id data) "Broken component" (:name component) id)
(assoc component :id id))
component))]
(update data :components #(d/mapm update-component %))))
(defn analyze-idless-components
"Scan all files to check if there are any one with idless components.
(Does not save the changes, only used to detect affected files)."
[file _]
(repair-idless-components (:data file)))
;; (defn check-image-shapes
;; [{:keys [data] :as file} stats]
;; (println "=> analizing file:" (:name file) (:id file))
@ -138,9 +159,11 @@
(loop [cursor (dt/now)
chunks 0]
(when (< chunks max-chunks)
(when-let [chunk (retrieve-chunk conn cursor)]
(let [cursor (-> chunk last :modified-at)]
(process-chunk chunk)
(Thread/sleep (inst-ms (dt/duration sleep)))
(recur cursor (inc chunks))))))
(let [chunk (retrieve-chunk conn cursor)]
(when-not (empty? chunk)
(let [cursor (-> chunk last :modified-at)]
(process-chunk chunk)
(Thread/sleep (inst-ms (dt/duration sleep)))
(recur cursor (inc chunks)))))))
@stats))))