Skip to content
Snippets Groups Projects
Unverified Commit e187fecd authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

Remove more misc unused code (#27131)

parent 66845647
No related merge requests found
......@@ -161,12 +161,6 @@
[arg]
(check arg generic-400))
(defmacro let-400
"Bind a form as with `let`; throw a 400 if it is `nil` or `false`."
{:style/indent 1}
[& body]
`(do-api-let ~generic-400 ~@body))
;; #### GENERIC 404 RESPONSE HELPERS
(def ^:private generic-404
[404 (deferred-tru "Not found.")])
......@@ -192,12 +186,6 @@
[arg]
(check arg (generic-403)))
(defmacro let-403
"Bind a form as with `let`; throw a 403 if it is `nil` or `false`."
{:style/indent 1}
[bindings & body]
`(do-api-let (generic-403) ~bindings ~@body))
(defn throw-403
"Throw a generic 403 (no permissions) error response."
([]
......@@ -216,12 +204,6 @@
[arg]
(check arg generic-500))
(defmacro let-500
"Bind a form as with `let`; throw a 500 if it is `nil` or `false`."
{:style/indent 1}
[bindings & body]
`(do-api-let ~generic-500 ~bindings ~@body))
(def generic-204-no-content
"A 'No Content' response for `DELETE` endpoints to return."
{:status 204, :body nil})
......@@ -523,22 +505,6 @@
(reconcile-position-for-collection! old-collection-id old-position nil)
(reconcile-position-for-collection! new-collection-id nil new-position))))))
(defmacro catch-and-raise
"Catches exceptions thrown in `body` and passes them along to the `raise` function. Meant for writing async
endpoints.
You only need to `raise` Exceptions that happen outside the initial thread of the API endpoint function; things like
normal permissions checks are usually done within the same thread that called the endpoint, meaning the middleware
that catches Exceptions will automatically handle them."
{:style/indent 1}
;; using 2+ args so we can catch cases where people forget to pass in `raise`
[raise body & more]
`(try
~body
~@more
(catch Throwable e#
(~raise e#))))
(defn bit->boolean
"Coerce a bit returned by some MySQL/MariaDB versions in some situations to Boolean."
[v]
......
......@@ -3,17 +3,17 @@
TODO -- these have nothing to do with the application database. This namespace should be renamed something like
`metabase.driver.util.metadata-queries`."
(:require [clojure.tools.logging :as log]
[metabase.driver :as driver]
[metabase.driver.util :as driver.u]
[metabase.models.table :as table :refer [Table]]
[metabase.query-processor :as qp]
[metabase.query-processor.interface :as qp.i]
[metabase.sync.interface :as i]
[metabase.util :as u]
[metabase.util.schema :as su]
[schema.core :as s]
[toucan.db :as db]))
(:require
[metabase.driver :as driver]
[metabase.driver.util :as driver.u]
[metabase.models.table :as table :refer [Table]]
[metabase.query-processor :as qp]
[metabase.query-processor.interface :as qp.i]
[metabase.sync.interface :as i]
[metabase.util :as u]
[metabase.util.schema :as su]
[schema.core :as s]
[toucan.db :as db]))
(defn- qp-query [db-id mbql-query]
{:pre [(integer? db-id)]}
......@@ -33,19 +33,6 @@
;; macro for building queries. Do not remove
(assoc mbql-query :source-table table-id)))
(defn table-row-count
"Fetch the row count of `table` via the query processor."
[table]
{:pre [(map? table)]
:post [(integer? %)]}
(let [results (qp-query (:db_id table) {:source-table (u/the-id table)
:aggregation [[:count]]})]
(try (-> results first first long)
(catch Throwable e
(log/error "Error fetching table row count. Query returned:\n"
(u/pprint-to-str results))
(throw e)))))
(def ^Integer absolute-max-distinct-values-limit
"The absolute maximum number of results to return for a `field-distinct-values` query. Normally Fields with 100 or
less values (at the time of this writing) get marked as `auto-list` Fields, meaning we save all their distinct
......
......@@ -6,17 +6,16 @@
SQL-based drivers can use the `:sql` driver as a parent, and JDBC-based SQL drivers can use `:sql-jdbc`. Both of
these drivers define additional multimethods that child drivers should implement; see [[metabase.driver.sql]] and
[[metabase.driver.sql-jdbc]] for more details."
(:require [clojure.string :as str]
[clojure.tools.logging :as log]
[java-time :as t]
[metabase.driver.impl :as driver.impl]
[metabase.models.setting :as setting :refer [defsetting]]
[metabase.plugins.classloader :as classloader]
[metabase.util.i18n :refer [deferred-tru trs tru]]
[metabase.util.schema :as su]
[potemkin :as p]
[schema.core :as s]
[toucan.db :as db]))
(:require
[clojure.string :as str]
[clojure.tools.logging :as log]
[java-time :as t]
[metabase.driver.impl :as driver.impl]
[metabase.models.setting :as setting :refer [defsetting]]
[metabase.plugins.classloader :as classloader]
[metabase.util.i18n :refer [deferred-tru trs tru]]
[potemkin :as p]
[toucan.db :as db]))
(declare notify-database-updated)
......@@ -305,41 +304,44 @@
(defmethod describe-table-fks ::driver [_ _ _]
nil)
(def ConnectionDetailsProperty
"Schema for a map containing information about a connection property we should ask the user to supply when setting up
;;; this is no longer used but we can leave it around for not for documentation purposes. Maybe we can actually do
;;; something useful with it like write a test that validates that drivers return correct connection details?
#_(def ConnectionDetailsProperty
"Schema for a map containing information about a connection property we should ask the user to supply when setting up
a new database, as returned by an implementation of `connection-properties`."
(s/constrained
{
;; The key that should be used to store this property in the `details` map.
:name su/NonBlankString
(s/constrained
{
;; The key that should be used to store this property in the `details` map.
:name su/NonBlankString
;; Human-readable name that should be displayed to the User in UI for editing this field.
:display-name su/NonBlankString
;; Human-readable name that should be displayed to the User in UI for editing this field.
:display-name su/NonBlankString
;; Human-readable text that gives context about a field's input.
(s/optional-key :helper-text) s/Str
;; Human-readable text that gives context about a field's input.
(s/optional-key :helper-text) s/Str
;; Type of this property. Defaults to `:string` if unspecified.
;; `:select` is a `String` in the backend.
(s/optional-key :type) (s/enum :string :integer :boolean :password :select :text)
;; Type of this property. Defaults to `:string` if unspecified.
;; `:select` is a `String` in the backend.
(s/optional-key :type) (s/enum :string :integer :boolean :password :select :text)
;; A default value for this field if the user hasn't set an explicit value. This is shown in the UI as a
;; placeholder.
(s/optional-key :default) s/Any
;; A default value for this field if the user hasn't set an explicit value. This is shown in the UI as a
;; placeholder.
(s/optional-key :default) s/Any
;; Placeholder value to show in the UI if user hasn't set an explicit value. Similar to `:default`, but this value
;; is *not* saved to `:details` if no explicit value is set. Since `:default` values are also shown as
;; placeholders, you cannot specify both `:default` and `:placeholder`.
(s/optional-key :placeholder) s/Any
;; Placeholder value to show in the UI if user hasn't set an explicit value. Similar to `:default`, but this value
;; is *not* saved to `:details` if no explicit value is set. Since `:default` values are also shown as
;; placeholders, you cannot specify both `:default` and `:placeholder`.
(s/optional-key :placeholder) s/Any
;; Is this property required? Defaults to `false`.
(s/optional-key :required?) s/Bool
;; Is this property required? Defaults to `false`.
(s/optional-key :required?) s/Bool
;; Any options for `:select` types
(s/optional-key :options) {s/Keyword s/Str}}
;; Any options for `:select` types
(s/optional-key :options) {s/Keyword s/Str}}
(complement (every-pred #(contains? % :default) #(contains? % :placeholder)))
"connection details that does not have both default and placeholder"))
(complement (every-pred #(contains? % :default) #(contains? % :placeholder)))
"connection details that does not have both default and placeholder"))
(defmulti connection-properties
"Return information about the connection properties that should be exposed to the user for databases that will use
......
(ns metabase.driver.ddl.concurrent
(:import [java.util.concurrent Callable Executors ExecutorService Future ThreadFactory]))
(defonce ^:private thread-factory
(reify ThreadFactory
(newThread [_ r]
(doto (Thread. r)
(.setName "ddl worker")
(.setDaemon true)))))
(defonce ^:private executor
(delay (Executors/newFixedThreadPool 3 ^ThreadFactory thread-factory)))
(defn submit-task
"Submit a task to the ddl threadpool."
^Future [^Callable f]
(let [task (bound-fn [] (f))]
(.submit ^ExecutorService @executor ^Callable task)))
......@@ -228,14 +228,6 @@
;; TODO - do we want to include tables that should be `:hidden`?
(db/select 'Table, :db_id id, :active true, {:order-by [[:%lower.display_name :asc]]}))
(defn schema-names
"Return a *sorted set* of schema names (as strings) associated with this `Database`."
[{:keys [id]}]
(when id
(apply sorted-set (db/select-field :schema 'Table
:db_id id
{:modifiers [:DISTINCT]}))))
(defn pk-fields
"Return all the primary key `Fields` associated with this `database`."
[{:keys [id]}]
......@@ -243,11 +235,6 @@
(when (seq table-ids)
(db/select 'Field, :table_id [:in table-ids], :semantic_type (mdb.u/isa :type/PK)))))
(defn schema-exists?
"Does `database` have any tables with `schema`?"
^Boolean [{:keys [id]}, schema]
(db/exists? 'Table :db_id id, :schema (some-> schema name)))
;;; -------------------------------------------------- JSON Encoder --------------------------------------------------
......
......@@ -9,10 +9,10 @@
[metabase.util.date-2 :as u.date]
[toucan.models :as models]))
(def dimension-types
"Possible values for `Dimension.type`"
#{:internal
:external})
;;; Possible values for Dimension.type :
;;;
;;; :internal
;;; :external
(models/defmodel Dimension :dimension)
......
......@@ -203,13 +203,6 @@
;;; ---------------------------------------------- Hydration / Util Fns ----------------------------------------------
(defn target
"Return the FK target `Field` that this `Field` points to."
[{:keys [semantic_type fk_target_field_id]}]
(when (and (isa? semantic_type :type/FK)
fk_target_field_id)
(db/select-one Field :id fk_target_field_id)))
(defn values
"Return the `FieldValues` associated with this `field`."
[{:keys [id]}]
......
......@@ -25,11 +25,6 @@
(is (= 1000
(metadata-queries/field-count (db/select-one Field :id (mt/id :checkins :venue_id)))))))
(deftest table-row-count-test
(mt/test-drivers (metadata-queries-test-drivers)
(is (= 1000
(metadata-queries/table-row-count (db/select-one Table :id (mt/id :checkins)))))))
(deftest field-distinct-values-test
(mt/test-drivers (metadata-queries-test-drivers)
(is (= [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment