From a5fc42cafa8a8713966e6daf012a9e4e0282a823 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 8 Feb 2024 10:48:21 +0100 Subject: [PATCH] :sparkles: Normalize ids parsing on srepl helpers --- backend/src/app/srepl/binfile.clj | 5 ++--- backend/src/app/srepl/components_v2.clj | 13 ++++--------- backend/src/app/srepl/helpers.clj | 6 +++--- backend/src/app/srepl/main.clj | 23 +++++++---------------- 4 files changed, 16 insertions(+), 31 deletions(-) diff --git a/backend/src/app/srepl/binfile.clj b/backend/src/app/srepl/binfile.clj index 02c78cc8d..ae203eb16 100644 --- a/backend/src/app/srepl/binfile.clj +++ b/backend/src/app/srepl/binfile.clj @@ -9,13 +9,12 @@ [app.binfile.v2 :as binfile.v2] [app.db :as db] [app.main :as main] + [app.srepl.helpers :as h] [cuerdas.core :as str])) (defn export-team! [team-id] - (let [team-id (if (string? team-id) - (parse-uuid team-id) - team-id)] + (let [team-id (h/parse-uuid team-id)] (binfile.v2/export-team! main/system team-id))) (defn import-team! diff --git a/backend/src/app/srepl/components_v2.clj b/backend/src/app/srepl/components_v2.clj index 3b145d1cd..63a63efed 100644 --- a/backend/src/app/srepl/components_v2.clj +++ b/backend/src/app/srepl/components_v2.clj @@ -13,6 +13,7 @@ [app.features.components-v2 :as feat] [app.main :as main] [app.rpc.commands.files-snapshot :as rpc] + [app.srepl.helpers :as h] [app.svgo :as svgo] [app.util.cache :as cache] [app.util.events :as events] @@ -280,9 +281,7 @@ skip-on-graphic-error? true}}] (l/dbg :hint "migrate:start" :rollback rollback?) (let [tpoint (dt/tpoint) - file-id (if (string? file-id) - (parse-uuid file-id) - file-id) + file-id (h/parse-uuid file-id) cache (if (int? cache) (cache/create :executor (::wrk/executor main/system) :max-items cache) @@ -315,9 +314,7 @@ (l/dbg :hint "migrate:start" :rollback rollback?) - (let [team-id (if (string? team-id) - (parse-uuid team-id) - team-id) + (let [team-id (h/parse-uuid team-id) stats (atom {}) tpoint (dt/tpoint) @@ -651,9 +648,7 @@ (defn restore-team! [team-id label & {:keys [rollback?] :or {rollback? true}}] - (let [team-id (if (string? team-id) - (parse-uuid team-id) - team-id) + (let [team-id (h/parse-uuid team-id) get-file-snapshots (fn [conn ids] diff --git a/backend/src/app/srepl/helpers.clj b/backend/src/app/srepl/helpers.clj index 9f9ccc7cc..fe39a9bc5 100644 --- a/backend/src/app/srepl/helpers.clj +++ b/backend/src/app/srepl/helpers.clj @@ -52,9 +52,9 @@ (defn parse-uuid [v] - (if (uuid? v) - v - (d/parse-uuid v))) + (if (string? v) + (d/parse-uuid v) + v)) (defn reset-file-data! "Hardcode replace of the data of one file." diff --git a/backend/src/app/srepl/main.clj b/backend/src/app/srepl/main.clj index 9539c79bc..2dfb8244e 100644 --- a/backend/src/app/srepl/main.clj +++ b/backend/src/app/srepl/main.clj @@ -141,9 +141,7 @@ "feature should be supported" (contains? cfeat/supported-features feature)) - (let [team-id (if (string? team-id) - (parse-uuid team-id) - team-id)] + (let [team-id (h/parse-uuid team-id)] (db/tx-run! main/system (fn [{:keys [::db/conn]}] (let [team (-> (db/get conn :team {:id team-id}) @@ -161,9 +159,7 @@ "feature should be supported" (contains? cfeat/supported-features feature)) - (let [team-id (if (string? team-id) - (parse-uuid team-id) - team-id)] + (let [team-id (h/parse-uuid team-id)] (db/tx-run! main/system (fn [{:keys [::db/conn]}] (let [team (-> (db/get conn :team {:id team-id}) @@ -262,18 +258,13 @@ {:columns [:profile-id]}) (map :profile-id))) - (parse-uuid [v] - (if (uuid? v) - v - (d/parse-uuid v))) - (resolve-dest [dest] (cond (uuid? dest) [dest] (string? dest) - (some-> dest parse-uuid resolve-dest) + (some-> dest h/parse-uuid resolve-dest) (nil? dest) (resolve-dest uuid/zero) @@ -311,18 +302,18 @@ (coll? param) (sequence (comp (mapcat resolve-team) - (keep parse-uuid)) + (keep h/parse-uuid)) param) (uuid? param) (resolve-team param) (string? param) - (some-> param parse-uuid resolve-team)) + (some-> param h/parse-uuid resolve-team)) (= op :profile-id) (if (coll? param) - (sequence (keep parse-uuid) param) + (sequence (keep h/parse-uuid) param) (resolve-dest param))))))] (->> (resolve-dest dest) @@ -332,7 +323,7 @@ (defn duplicate-team [team-id & {:keys [name]}] - (let [team-id (if (string? team-id) (parse-uuid team-id) team-id)] + (let [team-id (h/parse-uuid team-id)] (db/tx-run! main/system (fn [{:keys [::db/conn] :as cfg}] (db/exec-one! conn ["SET CONSTRAINTS ALL DEFERRED"])