mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 04:49:03 -05:00
✨ Improve storage/* features support on srepl helpers
This commit is contained in:
parent
e37fc00351
commit
84fd952471
2 changed files with 39 additions and 32 deletions
|
@ -11,6 +11,7 @@
|
||||||
[app.auth :refer [derive-password]]
|
[app.auth :refer [derive-password]]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.files.features :as ffeat]
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.pages.migrations :as pmg]
|
[app.common.pages.migrations :as pmg]
|
||||||
|
@ -21,8 +22,11 @@
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.db.sql :as sql]
|
[app.db.sql :as sql]
|
||||||
[app.main :refer [system]]
|
[app.main :refer [system]]
|
||||||
|
[app.rpc.commands.files :as files]
|
||||||
[app.rpc.queries.profile :as prof]
|
[app.rpc.queries.profile :as prof]
|
||||||
[app.util.blob :as blob]
|
[app.util.blob :as blob]
|
||||||
|
[app.util.objects-map :as omap]
|
||||||
|
[app.util.pointer-map :as pmap]
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[clojure.stacktrace :as strace]
|
[clojure.stacktrace :as strace]
|
||||||
|
@ -66,23 +70,33 @@
|
||||||
[system & {:keys [update-fn id save? migrate? inc-revn?]
|
[system & {:keys [update-fn id save? migrate? inc-revn?]
|
||||||
:or {save? false migrate? true inc-revn? true}}]
|
:or {save? false migrate? true inc-revn? true}}]
|
||||||
(db/with-atomic [conn (:app.db/pool system)]
|
(db/with-atomic [conn (:app.db/pool system)]
|
||||||
(let [file (db/get-by-id conn :file id {:for-update true})
|
(let [file (-> (db/get-by-id conn :file id {:for-update true})
|
||||||
file (-> file
|
(update :features db/decode-pgarray #{}))]
|
||||||
(update :features db/decode-pgarray #{})
|
(binding [*conn* conn
|
||||||
(update :data blob/decode)
|
pmap/*tracked* (atom {})
|
||||||
(cond-> migrate? (update :data pmg/migrate-data)))
|
pmap/*load-fn* (partial files/load-pointer conn id)
|
||||||
file (binding [*conn* conn]
|
ffeat/*wrap-with-pointer-map-fn*
|
||||||
(-> (update-fn file)
|
(if (contains? (:features file) "storage/pointer-map") pmap/wrap identity)
|
||||||
(cond-> inc-revn? (update :revn inc))))]
|
ffeat/*wrap-with-objects-map-fn*
|
||||||
(when save?
|
(if (contains? (:features file) "storage/objectd-map") omap/wrap identity)]
|
||||||
(let [features (db/create-array conn "text" (:features file))
|
(let [file (-> file
|
||||||
data (blob/encode (:data file))]
|
(update :data blob/decode)
|
||||||
(db/update! conn :file
|
(cond-> migrate? (update :data pmg/migrate-data))
|
||||||
{:data data
|
(update-fn)
|
||||||
:revn (:revn file)
|
(cond-> inc-revn? (update :revn inc)))]
|
||||||
:features features}
|
(when save?
|
||||||
{:id id})))
|
(let [features (db/create-array conn "text" (:features file))
|
||||||
file)))
|
data (blob/encode (:data file))]
|
||||||
|
(db/update! conn :file
|
||||||
|
{:data data
|
||||||
|
:revn (:revn file)
|
||||||
|
:features features}
|
||||||
|
{:id id})
|
||||||
|
|
||||||
|
(when (contains? (:features file) "storage/pointer-map")
|
||||||
|
(files/persist-pointers! conn id))))
|
||||||
|
|
||||||
|
(dissoc file :data))))))
|
||||||
|
|
||||||
(def ^:private sql:retrieve-files-chunk
|
(def ^:private sql:retrieve-files-chunk
|
||||||
"SELECT id, name, created_at, data FROM file
|
"SELECT id, name, created_at, data FROM file
|
||||||
|
|
|
@ -110,10 +110,10 @@
|
||||||
(if (contains? features "storage/objects-map")
|
(if (contains? features "storage/objects-map")
|
||||||
file
|
file
|
||||||
(-> file
|
(-> file
|
||||||
(update :data migrate-to-omap)
|
(update :data migrate)
|
||||||
(update :features conj "storage/objects-map"))))
|
(update :features conj "storage/objects-map"))))
|
||||||
|
|
||||||
(migrate-to-omap [data]
|
(migrate [data]
|
||||||
(-> data
|
(-> data
|
||||||
(update :pages-index update-vals #(update % :objects omap/wrap))
|
(update :pages-index update-vals #(update % :objects omap/wrap))
|
||||||
(update :components update-vals #(update % :objects omap/wrap))))]
|
(update :components update-vals #(update % :objects omap/wrap))))]
|
||||||
|
@ -125,24 +125,17 @@
|
||||||
|
|
||||||
(defn enable-pointer-map-feature-on-file!
|
(defn enable-pointer-map-feature-on-file!
|
||||||
[system & {:keys [save? id]}]
|
[system & {:keys [save? id]}]
|
||||||
(letfn [(update-file [{:keys [features id] :as file}]
|
(letfn [(update-file [{:keys [features] :as file}]
|
||||||
(if (contains? features "storage/pointer-map")
|
(if (contains? features "storage/pointer-map")
|
||||||
file
|
file
|
||||||
(-> file
|
(-> file
|
||||||
(update :data migrate-to-omap id)
|
(update :data migrate)
|
||||||
(update :features conj "storage/pointer-map"))))
|
(update :features conj "storage/pointer-map"))))
|
||||||
|
|
||||||
(migrate-to-omap [data file-id]
|
(migrate [data]
|
||||||
(binding [pmap/*tracked* (atom {})]
|
(-> data
|
||||||
(let [data (-> data
|
(update :pages-index update-vals pmap/wrap)
|
||||||
(update :pages-index update-vals pmap/wrap)
|
(update :components pmap/wrap)))]
|
||||||
(update :components pmap/wrap))]
|
|
||||||
(doseq [[id item] @pmap/*tracked*]
|
|
||||||
(db/insert! h/*conn* :file-data-fragment
|
|
||||||
{:id id
|
|
||||||
:file-id file-id
|
|
||||||
:content (-> item deref blob/encode)}))
|
|
||||||
data)))]
|
|
||||||
|
|
||||||
(h/update-file! system
|
(h/update-file! system
|
||||||
:id id
|
:id id
|
||||||
|
|
Loading…
Add table
Reference in a new issue