Should make page load faster
This commit is contained in:
@@ -36,7 +36,27 @@
|
||||
|
||||
{:db/ident :legal-entity-1099-type/none}
|
||||
{:db/ident :legal-entity-1099-type/misc}
|
||||
{:db/ident :legal-entity-1099-type/landlord}]]}})
|
||||
{:db/ident :legal-entity-1099-type/landlord}]]}
|
||||
:add-vendor-usages {:txes [[{:db/ident :vendor-usage/key
|
||||
:db/doc "A key to find this by, normally vendor (db:/id)-client(:db/id)"
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/unique :db.unique/identity}
|
||||
{:db/ident :vendor-usage/vendor
|
||||
:db/doc "Which vendor this usage is for"
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one}
|
||||
|
||||
{:db/ident :vendor-usage/client
|
||||
:db/doc "Which client this usage is for"
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one}
|
||||
{:db/ident :vendor-usage/count
|
||||
:db/doc "How many times does this client use this vendor"
|
||||
:db/valueType :db.type/long
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/noHistory true}]
|
||||
]}})
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
(defn <-datomic [a]
|
||||
(cond-> a
|
||||
(:vendor/legal-entity-tin-type a) (update :vendor/legal-entity-tin-type :db/ident)
|
||||
(:vendor/legal-entity-1099-type a) (update :vendor/legal-entity-1099-type :db/ident)))
|
||||
(:vendor/legal-entity-1099-type a) (update :vendor/legal-entity-1099-type :db/ident)
|
||||
true (assoc :usage (:vendor-usage/_vendor a))
|
||||
true (dissoc :vendor-usage/_vendor )))
|
||||
|
||||
(defn cleanse [id vendor]
|
||||
(let [clients (if-let [clients (limited-clients id)]
|
||||
@@ -27,7 +29,8 @@
|
||||
:vendor/automatically-paid-when-due [:db/id :client/name]
|
||||
:vendor/legal-entity-tin-type [:db/ident :db/id]
|
||||
:vendor/legal-entity-1099-type [:db/ident :db/id]
|
||||
:vendor/default-account [:db/id :account/numeric-code :account/name]}])
|
||||
:vendor/default-account [:db/id :account/numeric-code :account/name]
|
||||
:vendor-usage/_vendor [:vendor-usage/client :vendor-usage/count]}])
|
||||
|
||||
(defn get-usages [args]
|
||||
(->> (cond-> {:query {:find ['?v '?c '(count ?e)]
|
||||
@@ -55,6 +58,21 @@
|
||||
(update usages v (fnil conj []) {:client-id c :count cnt}))
|
||||
{})))
|
||||
|
||||
(defn trim-usage [v limited-clients]
|
||||
(->> (if limited-clients
|
||||
(update v :usage (fn [usages]
|
||||
(->> usages
|
||||
(filter (comp (set (map :db/id limited-clients)) :db/id :vendor-usage/client))
|
||||
(map (fn [u] {:client-id (:db/id (:vendor-usage/client u))
|
||||
:count (:vendor-usage/count u)})))))
|
||||
|
||||
(update v :usage (fn [usages]
|
||||
(->> usages
|
||||
(map (fn [u] {:client-id (:db/id (:vendor-usage/client u))
|
||||
:count (:vendor-usage/count u)}))))))
|
||||
|
||||
))
|
||||
|
||||
(defn get-graphql [args]
|
||||
(let [usages (time (get-usages args))]
|
||||
(->> (cond-> {:query {:find [(list 'pull '?e default-read)]
|
||||
@@ -65,7 +83,8 @@
|
||||
(map first)
|
||||
(map #(cleanse (:id args) %))
|
||||
(map <-datomic)
|
||||
(map #(assoc % :usage (get usages (:db/id %)))))))
|
||||
(map #(trim-usage % (limited-clients (:id args))))
|
||||
#_(map #(assoc % :usage (get usages (:db/id %)))))))
|
||||
|
||||
(defn get-by-id [id]
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
[auto-ap.yodlee.core2 :as yodlee2]
|
||||
[auto-ap.graphql.clients :as gq-clients]
|
||||
[auto-ap.background.invoices]
|
||||
[auto-ap.background.vendor :as vendor]
|
||||
[auto-ap.square.core :as square]
|
||||
[auto-ap.datomic.migrate :as migrate]
|
||||
[auto-ap.yodlee.import :as yodlee]
|
||||
@@ -33,6 +34,7 @@
|
||||
(not (env :run-web? )) (into [#'jetty])
|
||||
(not (env :run-background?)) (into [#'square/square-loader
|
||||
#'square/square-settlement-loader
|
||||
#'vendor/refresh-vendor-usages-worker
|
||||
#'ledger/touch-broken-ledger-worker
|
||||
#'ledger/process-txes-worker
|
||||
#'ledger/ledger-reconciliation-worker
|
||||
|
||||
Reference in New Issue
Block a user