From b2cbb1e60f99b98bbb3db9170a42150e7685fcf6 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 11 Oct 2022 14:54:15 +0200 Subject: [PATCH] :sparkles: Update srepl helpers --- backend/src/app/srepl/helpers.clj | 38 +++++++++++-------------------- backend/src/app/srepl/main.clj | 18 +++++++++++++++ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/backend/src/app/srepl/helpers.clj b/backend/src/app/srepl/helpers.clj index 87dbd8b68..3e89feb8d 100644 --- a/backend/src/app/srepl/helpers.clj +++ b/backend/src/app/srepl/helpers.clj @@ -66,17 +66,20 @@ (db/with-atomic [conn (:app.db/pool system)] (let [file (db/get-by-id conn :file id {:for-update true}) file (-> file + (update :features db/decode-pgarray #{}) (update :data blob/decode) - (cond-> migrate? (update :data pmg/migrate-data)) - (update :data update-fn) - (update :data blob/encode) + (cond-> migrate? (update :data pmg/migrate-data))) + file (-> (update-fn file) (cond-> inc-revn? (update :revn inc)))] (when save? - (db/update! conn :file - {:data (:data file) - :revn (:revn file)} - {:id (:id file)})) - (update file :data blob/decode)))) + (let [features (db/create-array conn "text" (:features file)) + data (blob/encode (:data file))] + (db/update! conn :file + {:data data + :revn (:revn file) + :features features} + {:id id}))) + file))) (def ^:private sql:retrieve-files-chunk "SELECT id, name, created_at, data FROM file @@ -122,27 +125,12 @@ (on-end state) state)))))) - -(defn analyze-file-data - [system & {:keys [id on-form on-data]}] - (let [file (get-file system id)] - (cond - (fn? on-data) - (on-data (:data file)) - - (fn? on-form) - (walk/postwalk (fn [form] - (on-form form) - form) - (:data file))) - nil)) - (defn update-pages "Apply a function to all pages of one file. The function receives a page and returns an updated page." [data f] - (update data :pages-index d/update-vals f)) + (update data :pages-index update-vals f)) (defn update-shapes "Apply a function to all shapes of one page The function receives a shape and returns an updated shape" [page f] - (update page :objects d/update-vals f)) + (update page :objects update-vals f)) diff --git a/backend/src/app/srepl/main.clj b/backend/src/app/srepl/main.clj index 4c788d01c..b11306488 100644 --- a/backend/src/app/srepl/main.clj +++ b/backend/src/app/srepl/main.clj @@ -16,6 +16,7 @@ [app.rpc.queries.profile :as profile] [app.srepl.fixes :as f] [app.srepl.helpers :as h] + [app.util.objects-map :as omap] [app.util.time :as dt] [clojure.pprint :refer [pprint]] [cuerdas.core :as str])) @@ -101,3 +102,20 @@ (db/update! conn :profile {:is-blocked true} {:id (:id profile)}) (db/delete! conn :http-session {:profile-id (:id profile)}) :blocked)))) + +(defn enable-objects-map-on-file + [system & {:keys [save? id]}] + (letfn [(update-file [{:keys [features] :as file}] + (if (contains? features "storage/objects-map") + file + (update file :data migrate-to-omap))) + + (migrate-to-omap [data] + (-> data + (update :pages-index update-vals #(update % :objects omap/wrap)) + (update :components update-vals #(update % :objects omap/wrap))))] + + (h/update-file! system + :id id + :update-fn update-file + :save? save?)))