makes the report load fast.
This commit is contained in:
@@ -462,20 +462,8 @@
|
|||||||
{:body
|
{:body
|
||||||
(into (list) (apply dc/q (read-string (get query-params "query" )) (into [(dc/db conn)] (read-string (get query-params "args" "[]")))))}))
|
(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 [_]
|
(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
|
account->numeric-code (into {} (seq (dc/q '[:find ?i ?n
|
||||||
:in $ [?a ...]
|
:in $ [?a ...]
|
||||||
:where [?i ?a ?n]]
|
:where [?i ?a ?n]]
|
||||||
@@ -503,7 +491,7 @@
|
|||||||
(map (fn [delta]
|
(map (fn [delta]
|
||||||
(atime/unparse-local (time/plus (time/floor (time/plus (atime/local-now) (time/days 1)) time/day) (time/days delta))
|
(atime/unparse-local (time/plus (time/floor (time/plus (atime/local-now) (time/days 1)) time/day) (time/days delta))
|
||||||
atime/iso-date))))]
|
atime/iso-date))))]
|
||||||
(alog/info ::continue-account-snapshot
|
(alog/info ::account-snapshot-report
|
||||||
:used-accounts (count used-accounts)
|
:used-accounts (count used-accounts)
|
||||||
:date-count (count dates))
|
:date-count (count dates))
|
||||||
{:status 200
|
{:status 200
|
||||||
@@ -524,23 +512,19 @@
|
|||||||
(let [[client account location date] (:journal-entry-line/client+account+location+date curr)
|
(let [[client account location date] (:journal-entry-line/client+account+location+date curr)
|
||||||
numeric-code (account->numeric-code account)]
|
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))))
|
(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)))
|
(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))]
|
|
||||||
a (sort-by account->numeric-code used-accounts)
|
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))
|
l (or (account->location a) (:client/locations client))
|
||||||
:when (and numeric-code (>= numeric-code 40000))
|
:when (and numeric-code (>= numeric-code 40000))
|
||||||
date-str dates]
|
date-str dates]
|
||||||
[(: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))
|
||||||
(with-precision 2
|
_ (when balance
|
||||||
(double (.setScale (bigdec (or
|
(reset! last-used-value balance))
|
||||||
(find-account-snapshot account-lookup-keys account-lookup-values (format "%d-%d-%s-%s" (:db/id client) numeric-code l date-str))
|
balance (or balance @last-used-value)]
|
||||||
0.0))
|
[(:client/code client) l numeric-code (account->name a) date-str
|
||||||
2 java.math.RoundingMode/HALF_UP)))]
|
(format "%.2f" balance)]))}))
|
||||||
#_(conj [(:client/code client) l numeric-code (account->name a) date-str]))}))
|
|
||||||
|
|
||||||
(defn wrap-predetermined-api-key [handler key]
|
(defn wrap-predetermined-api-key [handler key]
|
||||||
(fn [request]
|
(fn [request]
|
||||||
|
|||||||
Reference in New Issue
Block a user