                (jdbc/insert! *db* :series
                              {:series_name series-name}))))
 
-(defn intern-series-name [ series-name ]
-  (let [ series-name (.trim (name (or series-name ""))) ]
-    (if (= 0 (.length series-name))
-      nil
-      (with-transaction
-        (or (get-series-id series-name)
-            (add-series-name series-name))))))
+(def intern-series-name
+  (memoize
+   (fn [ series-name ]
+     (let [ series-name (.trim (name (or series-name ""))) ]
+       (if (= 0 (.length series-name))
+         nil
+         (with-transaction
+           (or (get-series-id series-name)
+               (add-series-name series-name))))))))
 
 (def latest-sample-times (atom {}))
 
 (defquery query-series-latest-sample-time [ series-name ]
   (if-let [ t (query-scalar *db* [(str "SELECT MAX(t) FROM sample"
                                        " WHERE series_id = ?")
-                                  (get-series-id series-name)])]
+                                  (intern-series-name series-name)])]
     t))
 
 (defn get-series-latest-sample-time [ series-name ]

      latest-t
      (let [query-latest-t (query-series-latest-sample-time series-name)]
        (swap! latest-sample-times assoc series-id query-latest-t)
        (log/info [:lst latest-sample-times])
        query-latest-t))))

(defn restrict-to-series [ samples series-name ]

      (app req))))

(defn call-with-query-logging [ name actual-args fn ]
  (log/trace "query" name actual-args)
  (let [begin-t (. System (nanoTime))
        result (fn)]
    (log/debug "query time" name "-" (/ (- (. System (nanoTime)) begin-t) 1000000.0))
