From 610f87b43dfc00b280a7f1a7ca73570445cc2e45 Mon Sep 17 00:00:00 2001
From: Cam Saul <1455846+camsaul@users.noreply.github.com>
Date: Tue, 13 Dec 2022 10:21:03 -0800
Subject: [PATCH] Remove more misc unused stuff (#27133)

---
 src/metabase/pulse/render/body.clj            |   4 -
 src/metabase/pulse/render/datetime.clj        | 109 ++----------------
 src/metabase/pulse/render/style.clj           |  12 --
 .../query_processor/middleware/log.clj        |  14 ---
 src/metabase/server/request/util.clj          |   5 -
 src/metabase/sync/interface.clj               |  40 ++-----
 test/metabase/pulse/render/datetime_test.clj  |  43 +------
 7 files changed, 21 insertions(+), 206 deletions(-)
 delete mode 100644 src/metabase/query_processor/middleware/log.clj

diff --git a/src/metabase/pulse/render/body.clj b/src/metabase/pulse/render/body.clj
index 9035e170635..199c8c9c73e 100644
--- a/src/metabase/pulse/render/body.clj
+++ b/src/metabase/pulse/render/body.clj
@@ -95,10 +95,6 @@
 
 ;;; --------------------------------------------------- Rendering ----------------------------------------------------
 
-(def ^:dynamic *render-img-fn*
-  "The function that should be used for rendering image bytes. Defaults to `render-img-data-uri`."
-  image-bundle/render-img-data-uri)
-
 (defn- create-remapping-lookup
   "Creates a map with from column names to a column index. This is used to figure out what a given column name or value
   should be replaced with"
diff --git a/src/metabase/pulse/render/datetime.clj b/src/metabase/pulse/render/datetime.clj
index 6c923b0ffcd..5487a5efa8b 100644
--- a/src/metabase/pulse/render/datetime.clj
+++ b/src/metabase/pulse/render/datetime.clj
@@ -1,19 +1,16 @@
 (ns metabase.pulse.render.datetime
   "Logic for rendering datetimes inside Pulses."
-  (:require [clojure.string :as str]
-            [clojure.tools.logging :as log]
-            [java-time :as t]
-            [metabase.public-settings :as public-settings]
-            [metabase.shared.models.visualization-settings :as mb.viz]
-            [metabase.util.date-2 :as u.date]
-            [metabase.util.i18n :refer [trs tru]]
-            [metabase.util.schema :as su]
-            [schema.core :as s])
-  (:import com.ibm.icu.text.RuleBasedNumberFormat
-           java.time.format.DateTimeFormatter
-           java.time.Period
-           java.time.temporal.Temporal
-           java.util.Locale))
+  (:require
+   [clojure.string :as str]
+   [java-time :as t]
+   [metabase.public-settings :as public-settings]
+   [metabase.shared.models.visualization-settings :as mb.viz]
+   [metabase.util.date-2 :as u.date]
+   [metabase.util.i18n :refer [tru]])
+  (:import
+   (com.ibm.icu.text RuleBasedNumberFormat)
+   (java.time.format DateTimeFormatter)
+   (java.util Locale)))
 
 (defn temporal-string?
   "Returns `true` if the string `s` is parseable as a datetime.
@@ -112,87 +109,3 @@
 
              ;; for everything else return in this format
              (reformat-temporal-str timezone-id s (str/replace (or date-style "MMM d, yyyy") #"D" "d")))))))
-
-(def ^:private RenderableInterval
-  {:interval-start     Temporal
-   :interval           Period
-   :this-interval-name su/NonBlankString
-   :last-interval-name su/NonBlankString})
-
-(defmulti ^:private renderable-interval
-  {:arglists '([unit])}
-  identity)
-
-(defmethod renderable-interval :default [_] nil)
-
-(s/defmethod renderable-interval :day :- RenderableInterval
-  [_]
-  {:interval-start     (u.date/truncate :day)
-   :interval           (t/days 1)
-   :this-interval-name (tru "Today")
-   :last-interval-name (tru "Yesterday")})
-
-(defn- start-of-this-week []
-  (u.date/truncate :week))
-
-(s/defmethod renderable-interval :week :- RenderableInterval
-  [_]
-  {:interval-start     (start-of-this-week)
-   :interval           (t/weeks 1)
-   :this-interval-name (tru "This week")
-   :last-interval-name (tru "Last week")})
-
-(s/defmethod renderable-interval :month :- RenderableInterval
-  [_]
-  {:interval-start     (u.date/truncate :month)
-   :interval           (t/months 1)
-   :this-interval-name (tru "This month")
-   :last-interval-name (tru "Last month")})
-
-(s/defmethod renderable-interval :quarter :- RenderableInterval
-  [_]
-  {:interval-start     (u.date/truncate :quarter)
-   :interval           (t/months 3)
-   :this-interval-name (tru "This quarter")
-   :last-interval-name (tru "Last quarter")})
-
-(s/defmethod renderable-interval :year :- RenderableInterval
-  [_]
-  {:interval-start     (u.date/truncate :year)
-   :interval           (t/years 1)
-   :this-interval-name (tru "This year")
-   :last-interval-name (tru "Last year")})
-
-(s/defn ^:private date->interval-name :- (s/maybe su/NonBlankString)
-  [t :- (s/maybe Temporal), unit :- (s/maybe s/Keyword)]
-  (when (and t unit)
-    (when-let [{:keys [interval-start interval this-interval-name last-interval-name]} (renderable-interval unit)]
-      (condp t/contains? t
-        (t/interval interval-start (t/plus interval-start interval))
-        this-interval-name
-
-        (t/interval (t/minus interval-start interval) interval-start)
-        last-interval-name
-
-        nil))))
-
-(s/defn format-temporal-str-relative :- (s/maybe su/NonBlankString)
-  "Formats timestamps with relative names (today, yesterday, this *, last *) based on column :unit, if possible,
-  otherwie returns nil"
-  [timezone-id s {:keys [unit]}]
-  (date->interval-name (u.date/parse s timezone-id) unit))
-
-(defn format-temporal-string-pair
-  "Formats a pair of temporal string literals (i.e., ISO-8601 strings) using relative formatting for the first
-  temporal values if possible, and 'Previous :unit' for the second; otherwise absolute instants in time for both."
-  [timezone-id [a b] col]
-  {:pre [((some-fn nil? string?) timezone-id)]}
-  (try
-    (if-let [a' (format-temporal-str-relative timezone-id a col)]
-      [a' (tru "Previous {0}" (-> col :unit name))]
-      [(format-temporal-str timezone-id a col) (format-temporal-str timezone-id b col)])
-    (catch Throwable _
-      ;; TODO  - there is code that calls this in `render.body` regardless of the types of values
-      (log/warn (trs "FIXME: These aren''t valid temporal literals: {0} {1}. Why are we attempting to format them as such?"
-                     (pr-str a) (pr-str b)))
-      nil)))
diff --git a/src/metabase/pulse/render/style.clj b/src/metabase/pulse/render/style.clj
index e9045406a00..0386e28408a 100644
--- a/src/metabase/pulse/render/style.clj
+++ b/src/metabase/pulse/render/style.clj
@@ -19,14 +19,6 @@
                       :when (seq v)]
                   (str (name k) ": " v ";"))))
 
-(def ^:const color-brand
-  "Classic Metabase blue."
-  "#2D86D4")
-
-(def ^:const color-purple
-  "Used as background color for cells in bar chart tables."
-  "#875DAF")
-
 (def ^:const color-gold
   "Used as color for 'We were unable to display this Pulse' messages."
   "#F9D45C")
@@ -35,10 +27,6 @@
   "Color for error messages."
   "#EF8C8C")
 
-(def ^:const color-gray-1
-  "~97% gray."
-  "#F8F8F8")
-
 (def ^:const color-gray-2
   "~75% gray."
   "#BDC1BF")
diff --git a/src/metabase/query_processor/middleware/log.clj b/src/metabase/query_processor/middleware/log.clj
deleted file mode 100644
index b79da31656f..00000000000
--- a/src/metabase/query_processor/middleware/log.clj
+++ /dev/null
@@ -1,14 +0,0 @@
-(ns metabase.query-processor.middleware.log
-  "Middleware for logging a query before it is processed.
-   (Various other middleware functions log the query as well in different stages.)"
-  (:require [clojure.tools.logging :as log]
-            [metabase.util :as u]))
-
-(defn- log-query* [query]
-  (u/prog1 query
-    (log/trace (u/format-color 'blue "\nQuery (before preprocessing): %s\n%s"  (u/emoji "😎") (u/pprint-to-str query)))))
-
-(defn log-query
-  "Middleware that logs the query that will be ran."
-  [qp]
-  (comp qp log-query*))
diff --git a/src/metabase/server/request/util.clj b/src/metabase/server/request/util.clj
index 0fef21f8a1d..5a9c1372870 100644
--- a/src/metabase/server/request/util.clj
+++ b/src/metabase/server/request/util.clj
@@ -68,11 +68,6 @@
     scheme
     (= scheme :https)))
 
-(defn protocol
-  "Protocol of this request, either `:http` or `:https`."
-  [request]
-  (if (https? request) :https :http))
-
 (defn embedded?
   "Whether this frontend client that made this request is embedded inside an `<iframe>`."
   [request]
diff --git a/src/metabase/sync/interface.clj b/src/metabase/sync/interface.clj
index 2a3246b3fbb..7146c6e7743 100644
--- a/src/metabase/sync/interface.clj
+++ b/src/metabase/sync/interface.clj
@@ -1,13 +1,12 @@
 (ns metabase.sync.interface
   "Schemas and constants used by the sync code."
-  (:require [clj-time.core :as time]
-            [metabase.models.database :refer [Database]]
-            [metabase.models.field :refer [Field]]
-            [metabase.models.interface :as mi]
-            [metabase.models.table :refer [Table]]
-            [metabase.util :as u]
-            [metabase.util.schema :as su]
-            [schema.core :as s]))
+  (:require
+   [metabase.models.database :refer [Database]]
+   [metabase.models.field :refer [Field]]
+   [metabase.models.interface :as mi]
+   [metabase.models.table :refer [Table]]
+   [metabase.util.schema :as su]
+   [schema.core :as s]))
 
 (def DatabaseMetadataTable
   "Schema for the expected output of `describe-database` for a Table."
@@ -61,12 +60,6 @@
   "Schema for the expected output of `describe-table-fks`."
   (s/maybe #{FKMetadataEntry}))
 
-(def TimeZoneId
-  "Schema predicate ensuring a valid time zone string"
-  (s/pred (fn [tz-str]
-            (u/ignore-exceptions (time/time-zone-for-id tz-str)))
-          'time/time-zone-for-id))
-
 ;; These schemas are provided purely as conveniences since adding `:import` statements to get the corresponding
 ;; classes from the model namespaces also requires a `:require`, which `clj-refactor` seems more than happy to strip
 ;; out from the ns declaration when running `cljr-clean-ns`. Plus as a bonus in the future we could add additional
@@ -82,25 +75,6 @@
 ;;; |                                            SAMPLING & FINGERPRINTS                                             |
 ;;; +----------------------------------------------------------------------------------------------------------------+
 
-(def FieldSample
-  "Schema for a sample of values returned by the `sample` sub-stage of analysis and passed into the `fingerprint`
-   stage. Guaranteed to be non-empty and non-nil."
-  ;; Validating against this is actually pretty quick, in the order of microseconds even for a 10,000 value sequence
-  (s/constrained [(s/pred (complement nil?))] seq "Non-empty sequence of non-nil values."))
-
-(def TableSample
-  "Schema for a sample of values of certain Fields for a TABLE. This should basically just be a sequence of rows where
-   each row is a sequence of values in the same order as the Fields passed in (basically the format you get from JDBC
-   when `:as-arrays?` is `false`).
-
-   e.g. if Fields passed in were `ID` and `Name` the Table sample should look something like:
-
-     [[1 \"Rasta Toucan\"]
-      [2 \"Lucky Pigeon\"]
-      [3 \"Parroty\"]]"
-  [[s/Any]])
-
-
 (def Percent
   "Schema for something represting a percentage. A floating-point value between (inclusive) 0 and 1."
   (s/constrained s/Num #(<= 0 % 1) "Valid percentage between (inclusive) 0 and 1."))
diff --git a/test/metabase/pulse/render/datetime_test.clj b/test/metabase/pulse/render/datetime_test.clj
index b5abbcce0dc..ec8ef357b12 100644
--- a/test/metabase/pulse/render/datetime_test.clj
+++ b/test/metabase/pulse/render/datetime_test.clj
@@ -1,48 +1,11 @@
 (ns metabase.pulse.render.datetime-test
-  (:require [clojure.test :refer :all]
-            [java-time :as t]
-            [metabase.pulse.render.datetime :as datetime]))
+  (:require
+   [clojure.test :refer :all]
+   [metabase.pulse.render.datetime :as datetime]))
 
 (def ^:private now "2020-07-16T18:04:00Z[UTC]")
 
-(defn- format-temporal-string-pair
-  [unit datetime-str-1 datetime-str-2]
-  (t/with-clock (t/mock-clock (t/zoned-date-time now) (t/zone-id "UTC"))
-    (datetime/format-temporal-string-pair "UTC" [datetime-str-1 datetime-str-2] {:unit unit})))
-
 ;; I don't know what exactly this is used for but we should at least make sure it's working correctly, see (#10326)
-(deftest format-temporal-string-pair-test
-  (testing "check that we can render relative timestamps for the various units we support"
-    (is (= ["Yesterday" "Previous day"]
-           (format-temporal-string-pair :day "2020-07-15T18:04:00Z" nil)))
-    (is (= ["Today" "Previous day"]
-           (format-temporal-string-pair :day now nil)))
-    (is (= ["Saturday, July 18, 2020" "Monday, July 20, 2020"]
-           (format-temporal-string-pair :day "2020-07-18T18:04:00Z" "2020-07-20T18:04:00Z")))
-    (is (= ["Last week" "Previous week"]
-           (format-temporal-string-pair :week "2020-07-09T18:04:00Z" nil)))
-    (is (= ["This week" "Previous week"]
-           (format-temporal-string-pair :week now nil)))
-    (is (= ["Week 5 - 2020" "Week 13 - 2020"]
-           (format-temporal-string-pair :week "2020-02-01T18:04:00Z" "2020-03-25T18:04:00Z")))
-    (is (= ["This month" "Previous month"]
-           (format-temporal-string-pair :month "2020-07-16T18:04:00Z" nil)))
-    (is (= ["This month" "Previous month"]
-           (format-temporal-string-pair :month now nil)))
-    (is (= ["July, 2021" "July, 2022"]
-           (format-temporal-string-pair :month "2021-07-16T18:04:00Z" "2022-07-16T18:04:00Z")))
-    (is (= ["Last quarter" "Previous quarter"]
-           (format-temporal-string-pair :quarter "2020-05-16T18:04:00Z" nil)))
-    (is (= ["This quarter" "Previous quarter"]
-           (format-temporal-string-pair :quarter now nil)))
-    (is (= ["Q3 - 2018" "Q3 - 2019"]
-           (format-temporal-string-pair :quarter "2018-07-16T18:04:00Z" "2019-07-16T18:04:00Z")))
-    (is (= ["Last year" "Previous year"]
-           (format-temporal-string-pair :year "2019-07-16T18:04:00Z" nil)))
-    (is (= ["This year" "Previous year"]
-           (format-temporal-string-pair :year now nil)))
-    (is (= ["2018" "2021"]
-           (format-temporal-string-pair :year "2018-07-16T18:04:00Z" "2021-07-16T18:04:00Z")))))
 
 (deftest format-temporal-str-test
   (testing "Null values do not blow up"
-- 
GitLab