From 090d162ec384badf779135d706196cfd62d938c8 Mon Sep 17 00:00:00 2001
From: Cam Saul <cammsaul@gmail.com>
Date: Fri, 5 Apr 2019 19:28:39 -0700
Subject: [PATCH] process-query-and-save-with-max! ->
 process-query-and-save-with-max-results-constraints!

---
 src/metabase/api/dataset.clj                           |  2 +-
 src/metabase/mbql/schema.clj                           |  2 +-
 src/metabase/pulse.clj                                 |  9 +++++----
 src/metabase/query_processor.clj                       |  2 +-
 src/metabase/query_processor/async.clj                 | 10 +++++-----
 .../metabase/query_processor_test/constraints_test.clj |  6 +++---
 6 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/metabase/api/dataset.clj b/src/metabase/api/dataset.clj
index 28024af1e50..4bfa5f7e343 100644
--- a/src/metabase/api/dataset.clj
+++ b/src/metabase/api/dataset.clj
@@ -47,7 +47,7 @@
   (let [source-card-id (query->source-card-id query)
         options        {:executed-by api/*current-user-id*, :context :ad-hoc,
                         :card-id     source-card-id,        :nested? (boolean source-card-id)}]
-    (qp.async/process-query-and-save-with-max! query options)))
+    (qp.async/process-query-and-save-with-max-results-constraints! query options)))
 
 
 ;;; ----------------------------------- Downloading Query Results in Other Formats -----------------------------------
diff --git a/src/metabase/mbql/schema.clj b/src/metabase/mbql/schema.clj
index a4a3499ec36..765b27c149d 100644
--- a/src/metabase/mbql/schema.clj
+++ b/src/metabase/mbql/schema.clj
@@ -656,7 +656,7 @@
           :question
           :xlsx-download))
 
-;; TODO - this schema is somewhat misleading because if you use a function like `qp/process-query-and-save-with-max!`
+;; TODO - this schema is somewhat misleading because if you use a function like `qp/process-query-and-save-with-max-results-constraints!`
 ;; some of these keys (e.g. `:context`) are in fact required
 (def Info
   "Schema for query `:info` dictionary, which is used for informational purposes to record information about how a query
diff --git a/src/metabase/pulse.clj b/src/metabase/pulse.clj
index 03972a4f517..1e4331c3ff7 100644
--- a/src/metabase/pulse.clj
+++ b/src/metabase/pulse.clj
@@ -33,10 +33,11 @@
     (when-let [card (Card :id card-id, :archived false)]
       (let [{:keys [creator_id dataset_query]} card]
         {:card   card
-         :result (qp/process-query-and-save-with-max! dataset_query (merge {:executed-by creator_id,
-                                                                            :context     :pulse,
-                                                                            :card-id     card-id}
-                                                                           options))}))
+         :result (qp/process-query-and-save-with-max-results-constraints! dataset_query
+                   (merge {:executed-by creator_id,
+                           :context     :pulse,
+                           :card-id     card-id}
+                          options))}))
     (catch Throwable t
       (log/warn t (trs "Error running query for Card {0}" card-id)))))
 
diff --git a/src/metabase/query_processor.clj b/src/metabase/query_processor.clj
index fd64e52000b..4794a3fbead 100644
--- a/src/metabase/query_processor.clj
+++ b/src/metabase/query_processor.clj
@@ -395,7 +395,7 @@
      {:max-results-bare-rows max-results})
    m))
 
-(s/defn process-query-and-save-with-max!
+(s/defn process-query-and-save-with-max-results-constraints!
   "Same as `process-query-and-save-execution!` but will include the default max rows returned as a constraint. (This
   function is ulitmately what powers most API endpoints that run queries, including `POST /api/dataset`.)"
   {:style/indent 1}
diff --git a/src/metabase/query_processor/async.clj b/src/metabase/query_processor/async.clj
index b829c6c3d7c..48ae9434910 100644
--- a/src/metabase/query_processor/async.clj
+++ b/src/metabase/query_processor/async.clj
@@ -70,12 +70,12 @@
   [query options]
   (do-async (:database query) qp/process-query-and-save-execution! query options))
 
-(defn process-query-and-save-with-max!
-  "Async version of `metabase.query-processor/process-query-and-save-with-max!`. Runs query asynchronously, and returns
-  a `core.async` channel that can be used to fetch the results once the query finishes running. Closing the channel
-  will cancel the query."
+(defn process-query-and-save-with-max-results-constraints!
+  "Async version of `metabase.query-processor/process-query-and-save-with-max-results-constraints!`. Runs query
+  asynchronously, and returns a `core.async` channel that can be used to fetch the results once the query finishes
+  running. Closing the channel will cancel the query."
   [query options]
-  (do-async (:database query) qp/process-query-and-save-with-max! query options))
+  (do-async (:database query) qp/process-query-and-save-with-max-results-constraints! query options))
 
 (defn process-query-without-save!
   "Async version of `metabase.query-processor/process-query-without-save!`. Runs query asynchronously, and returns a
diff --git a/test/metabase/query_processor_test/constraints_test.clj b/test/metabase/query_processor_test/constraints_test.clj
index 02978fc1c17..a25d8922a3a 100644
--- a/test/metabase/query_processor_test/constraints_test.clj
+++ b/test/metabase/query_processor_test/constraints_test.clj
@@ -29,8 +29,8 @@
        :native      (native-query)
        :constraints {:max-results 5}})))
 
-;; does it also work when running via `process-query-and-save-with-max!`, the function that powers endpoints like
-;; `POST /api/dataset`?
+;; does it also work when running via `process-query-and-save-with-max-results-constraints!`, the function that powers
+;; endpoints like `POST /api/dataset`?
 (qp.test/expect-with-non-timeseries-dbs
   [["Red Medicine"]
    ["Stout Burgers & Beers"]
@@ -38,7 +38,7 @@
    ["Wurstküche"]
    ["Brite Spot Family Restaurant"]]
   (qp.test/rows
-    (qp/process-query-and-save-with-max!
+    (qp/process-query-and-save-with-max-results-constraints!
         {:database    (data/id)
          :type        :native
          :native      (native-query)
-- 
GitLab