0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 00:10:11 -05:00

🐛 Fix broken restore snapshot function

This commit is contained in:
Andrey Antukh 2024-02-06 19:17:12 +01:00
parent a71e7f7906
commit 7a50cb3ff9

View file

@ -63,34 +63,38 @@
[{:keys [::db/conn ::sto/storage] :as cfg} {:keys [file-id id]}]
(let [storage (media/configure-assets-storage storage conn)
params {:id id :file-id file-id}
options {:columns [:id :data :revn]}
options {:columns [:id :data :revn :features]}
snapshot (db/get* conn :file-change params options)]
(when (and (some? snapshot)
(some? (:data snapshot)))
(l/debug :hint "snapshot found"
:snapshot-id (str (:id snapshot))
:file-id (str file-id))
(l/dbg :hint "restoring snapshot"
:file-id (str file-id)
:snapshot-id (str (:id snapshot)))
(db/update! conn :file
{:data (:data snapshot)}
{:data (:data snapshot)
:revn (:revn snapshot)
:features (:features snapshot)}
{:id file-id})
;; clean object thumbnails
(let [sql (str "delete from file_object_thumbnail "
(let [sql (str "update file_tagged_object_thumbnail "
" set deleted_at = now() "
" where file_id=? returning media_id")
res (db/exec! conn [sql file-id])]
(doseq [media-id (into #{} (keep :media-id) res)]
(sto/del-object! storage media-id)))
(sto/touch-object! storage media-id)))
;; clean object thumbnails
(let [sql (str "delete from file_thumbnail "
(let [sql (str "update file_thumbnail "
" set deleted_at = now() "
" where file_id=? returning media_id")
res (db/exec! conn [sql file-id])]
(doseq [media-id (into #{} (keep :media-id) res)]
(sto/del-object! storage media-id)))
(sto/touch-object! storage media-id)))
{:id (:id snapshot)})))