0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-15 03:28:25 -05:00

Merge pull request #4318 from penpot/niwinz-staging-bugfix-2

🐛 Several bugfixes
This commit is contained in:
Alejandro 2024-03-22 16:45:03 +01:00 committed by GitHub
commit 43d7d91415
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 73 additions and 57 deletions

View file

@ -62,6 +62,12 @@
{:id id :file-id file-id} {:id id :file-id file-id}
{::sql/columns [:content] {::sql/columns [:content]
::db/check-deleted false})] ::db/check-deleted false})]
(l/trc :hint "load pointer"
:file-id (str file-id)
:id (str id)
:found (some? content))
(when-not content (when-not content
(ex/raise :type :internal (ex/raise :type :internal
:code :fragment-not-found :code :fragment-not-found

View file

@ -35,15 +35,18 @@
(defn get-file (defn get-file
"Get the migrated data of one file." "Get the migrated data of one file."
([id] (get-file (or *system* main/system) id)) ([id] (get-file (or *system* main/system) id nil))
([system id] ([system id & {:keys [raw?] :as opts}]
(db/run! system (db/run! system
(fn [system] (fn [system]
(binding [pmap/*load-fn* (partial feat.fdata/load-pointer system id)] (let [file (files/get-file system id :migrate? false)]
(-> (files/get-file system id :migrate? false) (if raw?
(update :data feat.fdata/process-pointers deref) file
(update :data feat.fdata/process-objects (partial into {})) (binding [pmap/*load-fn* (partial feat.fdata/load-pointer system id)]
(fmg/migrate-file))))))) (-> file
(update :data feat.fdata/process-pointers deref)
(update :data feat.fdata/process-objects (partial into {}))
(fmg/migrate-file)))))))))
(defn update-file! (defn update-file!
[system {:keys [id] :as file}] [system {:keys [id] :as file}]
@ -166,7 +169,7 @@
(fsnap/take-file-snapshot! system {:file-id file-id :label label})) (fsnap/take-file-snapshot! system {:file-id file-id :label label}))
(let [conn (db/get-connection system) (let [conn (db/get-connection system)
file (get-file system file-id) file (get-file system file-id opts)
libs (when with-libraries? libs (when with-libraries?
(->> (files/get-file-libraries conn file-id) (->> (files/get-file-libraries conn file-id)
(into [file] (map (fn [{:keys [id]}] (into [file] (map (fn [{:keys [id]}]

View file

@ -429,7 +429,9 @@
(try (try
(l/trc :hint "process:file:start" :file-id (str file-id) :index idx) (l/trc :hint "process:file:start" :file-id (str file-id) :index idx)
(let [system (assoc main/system ::db/rollback rollback?)] (let [system (assoc main/system ::db/rollback rollback?)]
(db/tx-run! system h/process-file! file-id update-fn opts)) (db/tx-run! system (fn [system]
(binding [h/*system* system]
(h/process-file! system file-id update-fn opts)))))
(catch Throwable cause (catch Throwable cause
(l/wrn :hint "unexpected error on processing file (skiping)" (l/wrn :hint "unexpected error on processing file (skiping)"

View file

@ -65,19 +65,8 @@
:features (:features file) :features (:features file)
:version (:version file) :version (:version file)
:data (:data file)} :data (:data file)}
{:id id}))) {:id id}
{::db/return-keys true})))
(defn- process-file!
[cfg file]
(try
(let [file (decode-file cfg file)
file (clean-file! cfg file)]
(cfv/validate-file-schema! file)
(update-file! cfg file))
(catch Throwable cause
(l/err :hint "error on cleaning file (skiping)"
:file-id (str (:id file))
:cause cause))))
(def ^:private (def ^:private
sql:get-candidates sql:get-candidates
@ -118,13 +107,15 @@
unused (->> (db/exec! conn [sql:mark-file-media-object-deleted id ids]) unused (->> (db/exec! conn [sql:mark-file-media-object-deleted id ids])
(into #{} (map :id)))] (into #{} (map :id)))]
(l/dbg :hint "clean" :rel "file-media-object" :file-id (str id) :total (count unused))
(doseq [id unused] (doseq [id unused]
(l/trc :hint "mark deleted" (l/trc :hint "mark deleted"
:rel "file-media-object" :rel "file-media-object"
:id (str id) :id (str id)
:file-id (str id))) :file-id (str id)))
[(count unused) file])) file))
(def ^:private sql:mark-file-object-thumbnails-deleted (def ^:private sql:mark-file-object-thumbnails-deleted
"UPDATE file_tagged_object_thumbnail "UPDATE file_tagged_object_thumbnail
@ -149,13 +140,15 @@
unused (->> (db/exec! conn [sql:mark-file-object-thumbnails-deleted file-id ids]) unused (->> (db/exec! conn [sql:mark-file-object-thumbnails-deleted file-id ids])
(into #{} (map :object-id)))] (into #{} (map :object-id)))]
(l/dbg :hint "clean" :rel "file-object-thumbnail" :file-id (str file-id) :total (count unused))
(doseq [object-id unused] (doseq [object-id unused]
(l/trc :hint "mark deleted" (l/trc :hint "mark deleted"
:rel "file-tagged-object-thumbnail" :rel "file-tagged-object-thumbnail"
:object-id object-id :object-id object-id
:file-id (str file-id))) :file-id (str file-id)))
[(count unused) file])) file))
(def ^:private sql:mark-file-thumbnails-deleted (def ^:private sql:mark-file-thumbnails-deleted
"UPDATE file_thumbnail "UPDATE file_thumbnail
@ -168,13 +161,15 @@
(let [unused (->> (db/exec! conn [sql:mark-file-thumbnails-deleted id revn]) (let [unused (->> (db/exec! conn [sql:mark-file-thumbnails-deleted id revn])
(into #{} (map :revn)))] (into #{} (map :revn)))]
(l/dbg :hint "clean" :rel "file-thumbnail" :file-id (str id) :total (count unused))
(doseq [revn unused] (doseq [revn unused]
(l/trc :hint "mark deleted" (l/trc :hint "mark deleted"
:rel "file-thumbnail" :rel "file-thumbnail"
:revn revn :revn revn
:file-id (str id))) :file-id (str id)))
[(count unused) file])) file))
(def ^:private sql:get-files-for-library (def ^:private sql:get-files-for-library
@ -230,7 +225,9 @@
file (update file :data process-fdata unused)] file (update file :data process-fdata unused)]
[(count unused) file]))
(l/dbg :hint "clean" :rel "components" :file-id (str file-id) :total (count unused))
file))
(def ^:private sql:get-changes (def ^:private sql:get-changes
"SELECT id, data FROM file_change "SELECT id, data FROM file_change
@ -242,47 +239,52 @@
SET deleted_at = now() SET deleted_at = now()
WHERE file_id = ? WHERE file_id = ?
AND id != ALL(?::uuid[]) AND id != ALL(?::uuid[])
AND deleted_at IS NULL
RETURNING id") RETURNING id")
(def ^:private xf:collect-pointers
(comp (map :data)
(map blob/decode)
(mapcat feat.fdata/get-used-pointer-ids)))
(defn- clean-data-fragments! (defn- clean-data-fragments!
[{:keys [::db/conn]} {:keys [id data] :as file}] [{:keys [::db/conn]} {:keys [id] :as file}]
(let [used (->> (db/cursor conn [sql:get-changes id]) (let [used (into #{} xf:collect-pointers
(into (feat.fdata/get-used-pointer-ids data) (cons file (db/cursor conn [sql:get-changes id])))
(comp (map :data)
(map blob/decode)
(mapcat feat.fdata/get-used-pointer-ids))))
unused (let [ids (db/create-array conn "uuid" used)] unused (let [ids (db/create-array conn "uuid" used)]
(->> (db/exec! conn [sql:mark-deleted-data-fragments id ids]) (->> (db/exec! conn [sql:mark-deleted-data-fragments id ids])
(into #{} (map :id))))] (into #{} (map :id))))]
(l/dbg :hint "clean" :rel "file-data-fragment" :file-id (str id) :total (count unused))
(doseq [id unused] (doseq [id unused]
(l/trc :hint "mark deleted" (l/trc :hint "mark deleted"
:rel "file-data-fragment" :rel "file-data-fragment"
:id (str id) :id (str id)
:file-id (str id))) :file-id (str id)))))
[(count unused) file]))
(defn- clean-file!
[cfg {:keys [id] :as file}]
(let [[n1 file] (clean-file-media! cfg file)
[n2 file] (clean-file-thumbnails! cfg file)
[n3 file] (clean-file-object-thumbnails! cfg file)
[n4 file] (clean-deleted-components! cfg file)
[n5 file] (clean-data-fragments! cfg file)]
(l/dbg :hint "file clened"
:file-id (str id)
:modified-at (dt/format-instant (:modified-at file))
:media-objects n1
:thumbnails n2
:object-thumbnails n3
:components n4
:data-fragments n5)
(defn- clean-media!
[cfg file]
(let [file (->> file
(clean-file-media! cfg)
(clean-file-thumbnails! cfg)
(clean-file-object-thumbnails! cfg)
(clean-deleted-components! cfg))]
(cfv/validate-file-schema! file)
file)) file))
(defn- process-file!
[cfg file]
(try
(let [file (decode-file cfg file)
file (clean-media! cfg file)
file (update-file! cfg file)]
(clean-data-fragments! cfg file))
(catch Throwable cause
(l/err :hint "error on cleaning file (skiping)"
:file-id (str (:id file))
:cause cause))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; HANDLER ;; HANDLER
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -37,7 +37,6 @@
(:require (:require
[app.common.fressian :as fres] [app.common.fressian :as fres]
[app.common.logging :as l]
[app.common.transit :as t] [app.common.transit :as t]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.util.time :as dt] [app.util.time :as dt]
@ -78,8 +77,6 @@
IPointerMap IPointerMap
(load! [_] (load! [_]
(l/trace :hint "pointer-map:load" :id (str id))
(when-not *load-fn* (when-not *load-fn*
(throw (UnsupportedOperationException. "load is not supported when *load-fn* is not bind"))) (throw (UnsupportedOperationException. "load is not supported when *load-fn* is not bind")))

View file

@ -683,7 +683,6 @@
deleted (when dedupe deleted (when dedupe
(-> (db/exec-one! conn [sql:remove-not-started-tasks task queue label]) (-> (db/exec-one! conn [sql:remove-not-started-tasks task queue label])
:next.jdbc/update-count))] :next.jdbc/update-count))]
(l/trc :hint "submit task" (l/trc :hint "submit task"
:name task :name task
:queue queue :queue queue

View file

@ -189,7 +189,14 @@
(mf/use-fn (mf/use-fn
(mf/deps style-code markup-code images-data) (mf/deps style-code markup-code images-data)
(fn [] (fn []
(wapi/write-to-clipboard (gen-all-code style-code markup-code images-data)))) (wapi/write-to-clipboard (gen-all-code style-code markup-code images-data))
(let [origin (if (= :workspace from)
"workspace"
"viewer")]
(st/emit! (ptk/event ::ev/event
{::ev/name "copy-inspect-code"
::ev/origin origin
:type "all"})))))
;;handle-open-review ;;handle-open-review
;;(mf/use-fn ;;(mf/use-fn