Add minor performance enhancements on template setup service

This commit is contained in:
Andrey Antukh 2023-11-29 15:41:10 +01:00 committed by Andrés Moya
parent f5ec818fc7
commit 22757a449f

View file

@ -19,17 +19,18 @@
[datoteka.fs :as fs] [datoteka.fs :as fs]
[integrant.core :as ig])) [integrant.core :as ig]))
(def ^:private schema:template (def ^:private
[:map {:title "Template"} schema:template
[:id ::sm/word-string] (sm/define
[:name ::sm/word-string] [:map {:title "Template"}
[:file-uri ::sm/word-string]]) [:id ::sm/word-string]
[:name ::sm/word-string]
[:file-uri ::sm/word-string]]))
(def ^:private schema:templates (def ^:private
[:vector schema:template]) schema:templates
(sm/define
(def check-templates! [:vector schema:template]))
(sm/check-fn schema:templates))
(defmethod ig/init-key ::setup/templates (defmethod ig/init-key ::setup/templates
[_ _] [_ _]
@ -38,13 +39,13 @@
(dm/verify! (dm/verify!
"expected a valid templates file" "expected a valid templates file"
(check-templates! templates)) (sm/check! schema:templates templates))
(doseq [{:keys [id path] :as template} templates] (doseq [{:keys [id path] :as template} templates]
(let [path (or path (fs/join dest id))] (let [path (or path (fs/join dest id))]
(if (fs/exists? path) (if (fs/exists? path)
(l/debug :hint "template file" :id id :state "present" :path (dm/str path)) (l/dbg :hint "template file" :id id :state "present" :path (dm/str path))
(l/debug :hint "template file" :id id :state "absent")))) (l/dbg :hint "template file" :id id :state "absent"))))
templates)) templates))