makes the report load fast.

This commit is contained in:
Bryce
2023-08-21 21:27:06 -07:00
parent 52de2690b3
commit d0d654511d

View File

@@ -462,20 +462,8 @@
{:body
(into (list) (apply dc/q (read-string (get query-params "query" )) (into [(dc/db conn)] (read-string (get query-params "args" "[]")))))}))
(defn my-compare [^String a ^String b]
(.compareTo a b))
(defn find-account-snapshot [^java.util.ArrayList account-lookup-keys ^java.util.ArrayList account-snapshot-values v]
(let [best-index (java.util.Collections/binarySearch account-lookup-keys v compare)
best-index (if (neg? best-index)
(dec (Math/abs best-index)) ;; fill forward
best-index)
best-value (nth account-snapshot-values best-index)]
best-value))
(defn export-ntg-account-snapshot [_]
(alog/info ::starting-account-snapshot)
(let [clients (pull-many (dc/db conn) '[:db/id :client/code :client/locations] [#_[:client/code "NGAK"] [:client/code "NGOP"] [:client/code "NGRV"] [:client/code "NGE1"]])
(let [clients (pull-many (dc/db conn) '[:db/id :client/code :client/locations] [[:client/code "NGAK"] [:client/code "NGOP"] [:client/code "NGRV"] [:client/code "NGE1"]])
account->numeric-code (into {} (seq (dc/q '[:find ?i ?n
:in $ [?a ...]
:where [?i ?a ?n]]
@@ -503,7 +491,7 @@
(map (fn [delta]
(atime/unparse-local (time/plus (time/floor (time/plus (atime/local-now) (time/days 1)) time/day) (time/days delta))
atime/iso-date))))]
(alog/info ::continue-account-snapshot
(alog/info ::account-snapshot-report
:used-accounts (count used-accounts)
:date-count (count dates))
{:status 200
@@ -524,23 +512,19 @@
(let [[client account location date] (:journal-entry-line/client+account+location+date curr)
numeric-code (account->numeric-code account)]
(assoc acc (format "%d-%d-%s-%s" client numeric-code location (atime/unparse-local (clj-time.coerce/to-date-time date) atime/iso-date)) (:journal-entry-line/running-balance curr))))
(sorted-map)))
account-lookup-keys (java.util.ArrayList. (keys account-lookup))
account-lookup-values (java.util.ArrayList. (map second account-lookup))
_ (alog/info ::account-lookup-size
:size (count account-lookup))]
(sorted-map)))]
a (sort-by account->numeric-code used-accounts)
:let [numeric-code (account->numeric-code a)]
:let [last-used-value (atom 0.0)
numeric-code (account->numeric-code a)]
l (or (account->location a) (:client/locations client))
:when (and numeric-code (>= numeric-code 40000))
date-str dates]
[(:client/code client) l numeric-code (account->name a) date-str
(with-precision 2
(double (.setScale (bigdec (or
(find-account-snapshot account-lookup-keys account-lookup-values (format "%d-%d-%s-%s" (:db/id client) numeric-code l date-str))
0.0))
2 java.math.RoundingMode/HALF_UP)))]
#_(conj [(:client/code client) l numeric-code (account->name a) date-str]))}))
(let [balance (account-lookup (format "%d-%d-%s-%s" (:db/id client) numeric-code l date-str))
_ (when balance
(reset! last-used-value balance))
balance (or balance @last-used-value)]
[(:client/code client) l numeric-code (account->name a) date-str
(format "%.2f" balance)]))}))
(defn wrap-predetermined-api-key [handler key]
(fn [request]