Skip to content
Snippets Groups Projects
Unverified Commit e1e8e0c4 authored by John Swanson's avatar John Swanson Committed by GitHub
Browse files

Don't set `:max-rows` in search (#45443)

This was a huge footgun.

We were accidentally limiting *ALL* queries run in our transducer to
1000 results. This included the query to fetch permissions, so when we
checked permissions we were checking a small percentage of your *actual*
permissions (e.g. 1000 / ~6300 for me on stats).
parent 38039ecf
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,6 @@
[metabase.util.malli.schema :as ms]
[toucan2.core :as t2]
[toucan2.instance :as t2.instance]
[toucan2.jdbc.options :as t2.jdbc.options]
[toucan2.realize :as t2.realize]))
(set! *warn-on-reflection* true)
......@@ -443,7 +442,8 @@
{:select [nil]}
(= (count models) 1)
(search-query-for-model (first models) search-ctx)
(merge (search-query-for-model (first models) search-ctx)
{:limit search.config/*db-max-results*})
:else
{:select [:*]
......@@ -451,7 +451,8 @@
:let [query (search-query-for-model model search-ctx)]
:when (seq query)]
query))} :alias_is_required_by_sql_but_not_needed_here]]
:order-by order-clause})))
:order-by order-clause
:limit search.config/*db-max-results*})))
(defn- hydrate-user-metadata
"Hydrate common-name for last_edited_by and created_by from result."
......@@ -597,11 +598,9 @@
to-toucan-instance (fn [row]
(let [model (-> row :model search.config/model-to-db-model :db-model)]
(t2.instance/instance model row)))
reducible-results (reify clojure.lang.IReduceInit
(reduce [_this rf init]
(binding [t2.jdbc.options/*options* (assoc t2.jdbc.options/*options* :max-rows search.config/*db-max-results*)]
(reduce rf init (t2/reducible-query search-query)))))
reducible-results (t2/reducible-query search-query)
xf (comp
(take search.config/*db-max-results*)
(map t2.realize/realize)
(map to-toucan-instance)
(map #(if (and (t2/instance-of? :model/Collection %)
......@@ -626,6 +625,7 @@
(filter #(pos? (:score %))))
total-results (cond->> (scoring/top-results reducible-results search.config/max-filtered-results xf)
true hydrate-user-metadata
(:model-ancestors? search-ctx) (add-dataset-collection-hierarchy)
true (add-collection-effective-location)
true (map serialize))
......
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