From 8b0b1abdb3577a13c49096cdfd7c769b8df78d17 Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Tue, 2 Jun 2020 15:27:28 -0700 Subject: [PATCH] Print timing info for pelias requests. --- .../lemondronor/advisorycircular/pelias.cljs | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/lemondronor/advisorycircular/pelias.cljs b/src/main/lemondronor/advisorycircular/pelias.cljs index 63bcf48..978d483 100644 --- a/src/main/lemondronor/advisorycircular/pelias.cljs +++ b/src/main/lemondronor/advisorycircular/pelias.cljs @@ -14,6 +14,9 @@ (def base-pelias-url "http://lockheed.local:4000/v1") +(defn now [] + (.getTime (js/Date.))) + ;; Does an HTTP GET to a pelias API url. Returns a promise that ;; resolves to the API results. @@ -30,10 +33,14 @@ (defn nearby ([config lat lon options] (log-verbose "Performing nearby query %s %s %s" lat lon options) - (pelias-get (:url config) "nearby" - {:query (assoc options - :point.lat lat - :point.lon lon)}))) + (p/let [start (now) + result (pelias-get (:url config) "nearby" + {:query (assoc options + :point.lat lat + :point.lon lon)}) + end (now)] + (log-info "Nearby geo query took %s ms" (- end start)) + result))) ;; Performs a pelias "reverse" query. Retuns a promise that resolves @@ -42,7 +49,11 @@ (defn reverse ([config lat lon options] (log-verbose "Performing reverse query %s %s %s" lat lon options) - (pelias-get (:url config) "reverse" - {:query (assoc options - :point.lat lat - :point.lon lon)}))) + (p/let [start (now) + result (pelias-get (:url config) "reverse" + {:query (assoc options + :point.lat lat + :point.lon lon)}) + end (now)] + (log-info "Reverse geo query took %s ms" (- end start)) + result)))