(cloud) big performance improvements for page load.

This commit is contained in:
2023-04-06 14:38:22 -07:00
parent 2a0f736af7
commit 5561861d3d
10 changed files with 349 additions and 272 deletions

View File

@@ -3,12 +3,13 @@
[amazonica.aws.s3 :as s3]
[auto-ap.datomic :refer [audit-transact conn]]
[auto-ap.datomic.clients :as d-clients]
[iol-ion.tx :refer [upsert-entity]]
[auto-ap.graphql.utils
:refer [->graphql
assert-admin
attach-tracing-resolvers
can-see-client?
<-graphql
result->page
is-admin?]]
[auto-ap.routes.queries :as q]
[auto-ap.square.core :as square]
@@ -18,12 +19,12 @@
[clojure.set :as set]
[clojure.string :as str]
[clojure.tools.logging :as log]
[com.brunobonacci.mulog :as mu]
[datomic.client.api :as dc]
[unilog.context :as lc]
[iol-ion.tx :refer [random-tempid upsert-entity]]
[mount.core :as mount]
[yang.scheduler :as scheduler]
[iol-ion.tx :refer [random-tempid]]
[com.brunobonacci.mulog :as mu])
[unilog.context :as lc]
[yang.scheduler :as scheduler])
(:import
(java.util UUID)
(org.apache.commons.codec.binary Base64)))
@@ -200,23 +201,39 @@
(defn get-client [context _ _]
(->graphql
(->> (d-clients/get-all)
(filter #(can-see-client? (:id context) %))
(map (fn [c]
(update c :client/bank-accounts (fn [bas]
(map #(set/rename-keys % {:bank-account/use-date-instead-of-post-date? :use-date-instead-of-post-date}) bas)))))
(map (fn [c]
(if (is-admin? (:id context))
c
(-> c
(dissoc :client/yodlee-provider-accounts)
(dissoc :client/plaid-items)))))
(map (fn [c]
(update c :client/bank-accounts
(fn [bank-accounts]
(mapv (fn [ba]
(assoc ba :bank-account/yodlee-balance-old nil))
bank-accounts))))))))
(->> (d-clients/get-minimal)
(filter #(can-see-client? (:id context) %)))))
(defn get-admin-client [context {:keys [id]} _]
(assert-admin (:id context))
(->graphql
(-> (d-clients/get-by-id id)
(update :client/bank-accounts (fn [bas]
(map #(set/rename-keys % {:bank-account/use-date-instead-of-post-date? :use-date-instead-of-post-date}) bas))))))
(defn get-client-page [context args _]
(assert-admin (:id context))
(let [args (assoc args :id (:id context))
[clients clients-count] (d-clients/get-graphql-page (assoc (<-graphql (:filters args))
:id (:id context)))
clients (->> clients
(map (fn [c]
(update c :client/bank-accounts (fn [bas]
(map #(set/rename-keys % {:bank-account/use-date-instead-of-post-date? :use-date-instead-of-post-date}) bas)))))
(map (fn [c]
(if (is-admin? (:id context))
c
(-> c
(dissoc :client/yodlee-provider-accounts)
(dissoc :client/plaid-items)))))
(map (fn [c]
(update c :client/bank-accounts
(fn [bank-accounts]
(mapv (fn [ba]
(assoc ba :bank-account/yodlee-balance-old nil))
bank-accounts))))))]
(result->page clients clients-count :clients (:filters args))))
(def sales-summary-query
"[:find ?d4 (sum ?total) (sum ?tax) (sum ?tip) (sum ?service-charge) (sum ?discount) (sum ?returns)
@@ -437,6 +454,15 @@
:yodlee_provider_accounts {:type '(list :yodlee_provider_account)}
:plaid_items {:type '(list :plaid_item)}}}
:client_page
{:fields {:clients {:type '(list :client)}
:count {:type 'Int}
:total {:type 'Int}
:start {:type 'Int}
:end {:type 'Int}}}
:bank_account
{:fields {:id {:type :id}
:integration_status {:type :integration_status}
@@ -471,7 +497,14 @@
(def queries
{:client {:type '(list :client)
:resolve :get-client}})
:resolve :get-client}
:admin_client {:type :client
:args {:id {:type :id}}
:resolve :get-admin-client}
:client_page {:type :client_page
:args {:filters {:type :client_filters}}
:resolve :get-client-page}})
(def mutations
{:edit_client {:type :client
@@ -486,6 +519,13 @@
:match {:type 'String}
:id {:type :id}}}
:client_filters
{:fields {:code {:type 'String}
:name_like {:type 'String}
:start {:type 'Int}
:per_page {:type 'Int}
:sort {:type '(list :sort_item)}}}
:edit_square_location {:fields {:client_location {:type 'String}
:id {:type :id}}}
@@ -551,6 +591,8 @@
(def resolvers
{:get-client get-client
:get-admin-client get-admin-client
:get-client-page get-client-page
:mutation/edit-client edit-client
:mutation/setup-sales-queries setup-sales-queries})