Skip to content

Commit

Permalink
meta fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed May 13, 2024
1 parent de6005f commit 8ca7e86
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/compojure/api/meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,12 @@
(defn- route-args? [arg]
(not= arg []))

(defn- resolve-var [&env sym]
(when (symbol? sym)
(let [v (resolve &env sym)]
(when (var? v)
v))))

(def endpoint-vars (into #{}
(mapcat (fn [n]
(map #(symbol (name %) (name n))
Expand Down Expand Up @@ -759,14 +765,11 @@
(defn- static-middleware? [&env body]
(and (seq? body)
(boolean
(let [sym (first body)]
(when (symbol? sym)
(when-some [v (resolve &env sym)]
(when (var? v)
(when (middleware-vars (var->sym v))
(let [[_ path route-arg & args] body
[options body] (extract-parameters args true)]
(static-body? &env body))))))))))
(when-some [v (resolve-var &env (first body))]
(when (middleware-vars (var->sym v))
(let [[_ mid & body] body]
(and (static-form? &env mid)
(static-body? &env body))))))))

(def route-middleware-vars (into #{}
(mapcat (fn [n]
Expand Down Expand Up @@ -803,12 +806,6 @@
(= sym 'if))
(static-body? &env (next form)))))))))

(defn- resolve-var [&env sym]
(when (symbol? sym)
(let [v (resolve &env sym)]
(when (var? v)
v))))

(defn- static-resolved-form? [&env form]
(boolean
(or (and (seq? form)
Expand Down Expand Up @@ -1007,7 +1004,7 @@
(let [coach (some-> (System/getProperty "compojure.api.meta.static-context-coach")
edn/read-string)]
(if-not coach
(when (ffirst (reset-vals! warned-non-static? true))
(when (first (reset-vals! warned-non-static? true))
(println
(str (format "WARNING: Performance issue detected with compojure-api usage in %s.\n" (ns-name *ns*))
"To fix this warning, set: -Dcompojure.api.meta.static-context-coach={:default :print}.\n"
Expand Down

0 comments on commit 8ca7e86

Please sign in to comment.