Use JSON isntead of EDN for history, 10x speedup.

This commit is contained in:
John Wiseman 2020-05-25 15:39:07 -07:00
parent 7540a35af0
commit 4ee19d1a14

View File

@ -6,7 +6,6 @@
[cljs.reader :as reader] [cljs.reader :as reader]
[clojure.set :as set] [clojure.set :as set]
[clojure.string :as string] [clojure.string :as string]
[fipp.edn :as fippedn]
[kitchen-async.promise :as p] [kitchen-async.promise :as p]
[lemondronor.advisorycircular.adsbx :as adsbx] [lemondronor.advisorycircular.adsbx :as adsbx]
[lemondronor.advisorycircular.generation :as generation] [lemondronor.advisorycircular.generation :as generation]
@ -157,7 +156,7 @@
(defn write-history-db [db path] (defn write-history-db [db path]
(fs/writeFileSync path (with-out-str (fippedn/pprint db))) (fs/writeFileSync path (.stringify js/JSON (clj->js db) nil " "))
db) db)
@ -165,8 +164,8 @@
;; resolves to the database value. ;; resolves to the database value.
(defn read-history-db [path] (defn read-history-db [path]
(p/let [edn-str (util/read-file path {:encoding "utf-8"}) (p/let [json-str (util/read-file path {:encoding "utf-8"})
db (reader/read-string edn-str)] db (js->clj (.parse js/JSON json-str))]
(log-verbose "Loaded %s aircraft from database %s" (count db) path) (log-verbose "Loaded %s aircraft from database %s" (count db) path)
db)) db))
@ -265,11 +264,6 @@
v))) v)))
(defn debug-prn [x msg]
(println msg (with-out-str (fippedn/pprint x)))
x)
(defn closest-airport [config lat lon] (defn closest-airport [config lat lon]
(p/let [results (pelias/nearby (:pelias config) (p/let [results (pelias/nearby (:pelias config)
lat lon lat lon
@ -566,7 +560,7 @@
;; close to an airport, then it's probably just doing flight ;; close to an airport, then it's probably just doing flight
;; training. ;; training.
:minimum-airport-distance-km 2.5 :minimum-airport-distance-km 2.5
:history-db-path "advisorycircular.edn" :history-db-path "advisorycircular.json"
:basestation-sqb "basestation.sqb" :basestation-sqb "basestation.sqb"
:twitter {:enabled? true}}) :twitter {:enabled? true}})
@ -634,7 +628,7 @@
(.option "--no-tweeting" "Do not tweet") (.option "--no-tweeting" "Do not tweet")
(.option "--config <path>" "Path to the configuration yaml file") (.option "--config <path>" "Path to the configuration yaml file")
(.option "--secrets <path>" "Path to the secrets yaml file" "secrets.yaml") (.option "--secrets <path>" "Path to the secrets yaml file" "secrets.yaml")
(.option "--history <path>" "Path to history/state file" "advisorycircular.edn") (.option "--history <path>" "Path to history/state file" "advisorycircular.json")
(.option "--log-prefix <prefix>" "Log prefix to use") (.option "--log-prefix <prefix>" "Log prefix to use")
(.parse (.-argv js/process))) (.parse (.-argv js/process)))
(logging/set-log-prefix! (or (.-logPrefix commander) "")) (logging/set-log-prefix! (or (.-logPrefix commander) ""))