Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Replace nano-id dependency with already included Encore (#66413)

Oleksandr Yakushevc9f40f60fcec
diff --git a/deps.edn b/deps.edn
index f8330dffce1..b407c435816 100644
--- a/deps.edn
+++ b/deps.edn
@@ -63,6 +63,7 @@
{:mvn/version "1.0.1"} ; Snowplow analytics
com.sun.mail/jakarta.mail ^:antq/exclude ; 2+ changes imports from javax.mail to jakarta.mail
{:mvn/version "1.6.8"} ; SMTP lib, required by postal
+ com.taoensso/encore {:mvn/version "3.158.0"} ; Utilities library (used by Nippy)
com.taoensso/nippy {:mvn/version "3.6.0"} ; Fast serialization (i.e., GZIP) library for Clojure
com.vladsch.flexmark/flexmark {:mvn/version "0.64.8"} ; Markdown parsing
com.vladsch.flexmark/flexmark-ext-autolink
@@ -109,7 +110,6 @@
metabase/throttle {:mvn/version "1.0.2"} ; Tools for throttling access to API endpoints and other code pathways
methodical/methodical {:mvn/version "1.0.127"} ; drop-in replacements for Clojure multimethods and adds several advanced features
metosin/malli {:mvn/version "0.20.0"} ; Data-driven Schemas for Clojure/Script and babashka
- nano-id/nano-id {:mvn/version "1.1.0"} ; NanoID generator for generating entity_ids
net.cgrand/macrovich {:mvn/version "0.2.2"} ; utils for writing macros for both Clojure & ClojureScript
net.clojars.wkok/openai-clojure {:mvn/version "0.23.0"
:exclusions [lambdaisland/uri]} ; OpenAI
diff --git a/enterprise/backend/src/metabase_enterprise/semantic_search/index.clj b/enterprise/backend/src/metabase_enterprise/semantic_search/index.clj
index 797b6b352e2..5292b45c93d 100644
--- a/enterprise/backend/src/metabase_enterprise/semantic_search/index.clj
+++ b/enterprise/backend/src/metabase_enterprise/semantic_search/index.clj
@@ -18,7 +18,6 @@
[metabase.util :as u]
[metabase.util.json :as json]
[metabase.util.log :as log]
- [nano-id.core :as nano-id]
[next.jdbc :as jdbc]
[next.jdbc.result-set :as jdbc.rs]
[toucan2.core :as t2])
@@ -49,7 +48,7 @@
"Schema for the index table."
[vector-dimensions]
;; Generate unique constraint name to avoid index name conflicts between multiple test tables
- (let [unique-constraint-name (keyword (str "unique_constraint_" (nano-id/nano-id) "_model_model_id"))]
+ (let [unique-constraint-name (keyword (str "unique_constraint_" (u/generate-nano-id) "_model_model_id"))]
[[:id :bigint [:primary-key] [:raw "GENERATED BY DEFAULT AS IDENTITY"]]
[:model :text :not-null]
[:model_id :text :not-null]
diff --git a/src/metabase/actions/actions.clj b/src/metabase/actions/actions.clj
index a71c90d4ce0..6966d6f3e4f 100644
--- a/src/metabase/actions/actions.clj
+++ b/src/metabase/actions/actions.clj
@@ -22,7 +22,6 @@
[metabase.util.malli :as mu]
[metabase.util.malli.registry :as mr]
[methodical.core :as methodical]
- [nano-id.core :as nano-id]
[toucan2.core :as t2])
(:import
(clojure.lang ExceptionInfo)))
@@ -180,7 +179,7 @@
inputs :- [:sequential :map]
& {:as _opts}]
(lib-be/with-metadata-provider-cache
- (let [invocation-id (nano-id/nano-id)
+ (let [invocation-id (u/generate-nano-id)
context-before (-> (assoc ctx :invocation-id invocation-id)
(update :invocation-stack u/conjv [action-kw invocation-id]))]
(log/debug "Started perform action")
diff --git a/src/metabase/util.cljc b/src/metabase/util.cljc
index 8c7d681cd45..2a2941ee908 100644
--- a/src/metabase/util.cljc
+++ b/src/metabase/util.cljc
@@ -31,8 +31,8 @@
[metabase.util.number :as u.number]
[metabase.util.performance :as perf :refer [#?(:clj for)]]
[metabase.util.polyfills]
- [nano-id.core :as nano-id]
[net.cgrand.macrovich :as macros]
+ [taoensso.encore :as encore]
[weavejester.dependency :as dep])
#?(:clj (:import
(clojure.core.protocols CollReduce)
@@ -1266,17 +1266,14 @@
If an argument is provided, it's taken to be an identity-hash string and used to seed the RNG,
producing the same value every time. This is only supported on the JVM!"
- ([] (nano-id/nano-id))
+ ([] (encore/nanoid))
([seed-str]
#?(:clj (let [seed (Long/parseLong seed-str 16)
rnd (Random. seed)
- gen (nano-id/custom
- "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
- 21
- (fn [len]
- (let [ba (byte-array len)]
- (.nextBytes rnd ba)
- ba)))]
+ gen (encore/rand-id-fn {:rand-bytes-fn (fn [len]
+ (let [ba (byte-array len)]
+ (.nextBytes rnd ba)
+ ba))})]
(gen))
:cljs (throw (ex-info "Seeded NanoIDs are not supported in CLJS" {:seed-str seed-str})))))