Skip to content
Snippets Groups Projects
Commit ab0a78af authored by Cam Saül's avatar Cam Saül
Browse files

don't make a connection pool for temp DBs

parent d1f340d7
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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."
......
......@@ -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"})))
......
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