From ab0a78afcca36c0d1fb47a27ccc668b9d190927c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cam=20Sau=CC=88l?= <cammsaul@gmail.com> Date: Thu, 9 Jul 2015 21:45:01 -0700 Subject: [PATCH] don't make a connection pool for temp DBs --- src/metabase/driver/generic_sql/util.clj | 11 ++++++----- test/metabase/test/data/h2.clj | 7 ++++--- test/metabase/test/data/postgres.clj | 7 ++++--- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/metabase/driver/generic_sql/util.clj b/src/metabase/driver/generic_sql/util.clj index 603a6de3780..c749b07a435 100644 --- a/src/metabase/driver/generic_sql/util.clj +++ b/src/metabase/driver/generic_sql/util.clj @@ -10,14 +10,15 @@ [metabase.driver.query-processor :as qp])) ;; Cache the Korma DB connections for a given Database for 60 seconds instead of creating new ones every single time -(defn- db->connection-spec [database] +(defn- db->connection-spec [{{:keys [short-lived?]} :details, :as database}] (let [driver (driver/engine->driver (:engine database)) database->connection-details (:database->connection-details driver) connection-details->connection-spec (:connection-details->connection-spec driver)] - (-> database - database->connection-details - connection-details->connection-spec - (assoc :make-pool? true)))) ; need to make a pool or the connection will be closed before we get a chance to unCLOB-er the results during JSON serialization + (merge (-> database database->connection-details connection-details->connection-spec) + ;; unless this is a temp DB, we need to make a pool or the connection will be closed before we get a chance to unCLOB-er the results during JSON serialization + ;; TODO - what will we do once we have CLOBS in temp DBs? + (when-not short-lived? + {:make-pool? true})))) (def ^{:arglists '([database])} db->korma-db diff --git a/test/metabase/test/data/h2.clj b/test/metabase/test/data/h2.clj index 3a6e869dc43..928207f7242 100644 --- a/test/metabase/test/data/h2.clj +++ b/test/metabase/test/data/h2.clj @@ -33,10 +33,11 @@ (defn- connection-details "Return a Metabase `Database.details` for H2 database defined by DATABASE-DEFINITION." - [^DatabaseDefinition database-definition] - {:db (format (if (:short-lived? database-definition) "file:%s" ; for short-lived connections don't create a server thread and don't use a keep-alive connection + [^DatabaseDefinition {:keys [short-lived?], :as database-definition}] + {:db (format (if short-lived? "file:%s" ; for short-lived connections don't create a server thread and don't use a keep-alive connection "file:%s;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1") - (filename database-definition))}) + (filename database-definition)) + :short-lived? short-lived?}) (defn- korma-connection-pool "Return an H2 korma connection pool to H2 database defined by DATABASE-DEFINITION." diff --git a/test/metabase/test/data/postgres.clj b/test/metabase/test/data/postgres.clj index a77e13c5b17..8372b13fcb9 100644 --- a/test/metabase/test/data/postgres.clj +++ b/test/metabase/test/data/postgres.clj @@ -23,9 +23,10 @@ :TextField "TEXT" :TimeField "TIME"}) -(defn- pg-connection-details [^DatabaseDefinition database-definition] - (merge {:host "localhost" - :port 5432} +(defn- pg-connection-details [^DatabaseDefinition {:keys [short-lived?]}] + (merge {:host "localhost" + :port 5432 + :short-lived? short-lived?} ;; HACK (when (env :circleci) {:user "ubuntu"}))) -- GitLab