Skip to content
Snippets Groups Projects
Unverified Commit 61e6bccb authored by Cam Saul's avatar Cam Saul
Browse files

Fix metabase namespaces seq if source files are omitted

parent 129fdf5c
Branches
Tags v0.33.7.1
No related merge requests found
......@@ -308,7 +308,8 @@
;; build the uberjar with `lein uberjar`
:uberjar
{:auto-clean true
:aot :all}
:aot :all
:omit-source true}
;; generate sample dataset with `lein generate-sample-dataset`
:generate-sample-dataset
......
......@@ -10,6 +10,7 @@
[clojure.math.numeric-tower :as math]
[clojure.tools.logging :as log]
[clojure.tools.namespace.find :as ns-find]
[clojure.tools.reader.edn :as edn]
[colorize.core :as colorize]
[flatland.ordered.map :refer [ordered-map]]
[medley.core :as m]
......@@ -488,18 +489,36 @@
(or (id object-or-id)
(throw (Exception. (tru "Not something with an ID: {0}" object-or-id)))))
(defn- metabase-namespace-symbs* []
(vec (sort (for [ns-symb (ns-find/find-namespaces (classpath/system-classpath))
:when (and (.startsWith (name ns-symb) "metabase.")
(not (.contains (name ns-symb) "test")))]
ns-symb))))
(def ^:private namespace-symbs-filename "resources/namespaces.edn")
(when *compile-files*
(printf "Saving list of Metabase namespaces to %s...\n" namespace-symbs-filename)
(spit namespace-symbs-filename (with-out-str (pprint (metabase-namespace-symbs*)))))
(def metabase-namespace-symbols
"Delay to a vector of symbols of all Metabase namespaces, excluding test namespaces.
This is intended for use by various routines that load related namespaces, such as task and events initialization.
Using `ns-find/find-namespaces` is fairly slow, and can take as much as half a second to iterate over the thousand
or so namespaces that are part of the Metabase project; use this instead for a massive performance increase."
;; We want to give JARs in the ./plugins directory a chance to load. At one point we have this as a future so it
;; start looking for things in the background while other stuff is happening but that meant plugins couldn't
;; introduce new Metabase namespaces such as drivers.
(delay (vec (for [ns-symb (ns-find/find-namespaces (classpath/system-classpath))
:when (and (.startsWith (name ns-symb) "metabase.")
(not (.contains (name ns-symb) "test")))]
ns-symb))))
"Delay to a vector of symbols of all Metabase namespaces, excluding test namespaces. This is intended for use by
various routines that load related namespaces, such as task and events initialization."
;; When building the uberjar we'll determine the symbols ahead of time ans save to an EDN file which will speed up
;; initialization a bit and also fix an issue where the sequence would be empty if `:omit-source` was enabled.
;; `ns-find` looks for Clojure source files.
;;
;; Use a delay for dev runs since `ns-find` is slow and can take several seconds or more
(if config/is-prod?
(delay
(try
(log/info (trs "Reading Metabase namespaces from {0}" namespace-symbs-filename))
(edn/read-string (slurp namespace-symbs-filename))
(catch Throwable e
(log/error e (trs "Failed to read Metabase namespaces from {0}" namespace-symbs-filename))
(metabase-namespace-symbs*))))
(delay
(metabase-namespace-symbs*))))
(def ^java.util.regex.Pattern uuid-regex
"A regular expression for matching canonical string representations of UUIDs."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment