(cloud) big performance improvements for page load.
This commit is contained in:
@@ -1,10 +1,46 @@
|
||||
(ns auto-ap.datomic.clients
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[auto-ap.datomic :refer [add-sorter-fields
|
||||
apply-pagination
|
||||
apply-sort-3
|
||||
conn
|
||||
merge-query
|
||||
pull-many]]
|
||||
[auto-ap.graphql.utils :refer [can-see-client? limited-clients]]
|
||||
[auto-ap.search :as search]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.string :as str]
|
||||
[datomic.client.api :as dc]))
|
||||
[datomic.client.api :as dc]
|
||||
[com.brunobonacci.mulog :as mu]))
|
||||
|
||||
(def full-read '[*
|
||||
{:client/square-integration-status [:integration-status/message
|
||||
:integration-status/last-attempt
|
||||
:integration-status/last-updated
|
||||
:db/id
|
||||
{:integration-status/state [:db/ident]}]}
|
||||
{:client/address [*]}
|
||||
{:client/square-locations [:square-location/square-id
|
||||
:square-location/name
|
||||
:square-location/client-location
|
||||
:db/id]}
|
||||
|
||||
{:client/ezcater-locations [{:ezcater-location/caterer [:ezcater-caterer/name :db/id]}
|
||||
:ezcater-location/location
|
||||
:db/id]}
|
||||
{:client/bank-accounts [* {:bank-account/type [*]
|
||||
:bank-account/yodlee-account [:yodlee-account/name :yodlee-account/id :yodlee-account/number]
|
||||
:bank-account/plaid-account [:plaid-account/name :db/id :plaid-account/number :plaid-account/balance]
|
||||
:bank-account/intuit-bank-account [:intuit-bank-account/name :intuit-bank-account/external-id :db/id]
|
||||
:bank-account/integration-status [:integration-status/message
|
||||
:db/id
|
||||
:integration-status/last-attempt
|
||||
:integration-status/last-updated
|
||||
{:integration-status/state [:db/ident]}]}
|
||||
]}
|
||||
{:yodlee-provider-account/_client [*]}
|
||||
{:plaid-item/_client [*]}
|
||||
{:client/emails [:db/id :email-contact/email :email-contact/description]}])
|
||||
|
||||
(defn cleanse [e]
|
||||
(-> e
|
||||
@@ -29,52 +65,25 @@
|
||||
(update :bank-account/sort-order (fn [so] (or so i)))))
|
||||
(range) bas)))))
|
||||
(defn get-all []
|
||||
(->> (dc/q '[:find (pull ?e [*
|
||||
{:client/square-integration-status [:integration-status/message
|
||||
:integration-status/last-attempt
|
||||
:integration-status/last-updated
|
||||
:db/id
|
||||
{:integration-status/state [:db/ident]}]}
|
||||
{:client/address [*]}
|
||||
{:client/square-locations [:square-location/square-id
|
||||
:square-location/name
|
||||
:square-location/client-location
|
||||
:db/id]}
|
||||
|
||||
{:client/ezcater-locations [{:ezcater-location/caterer [:ezcater-caterer/name :db/id]}
|
||||
:ezcater-location/location
|
||||
:db/id]}
|
||||
{:client/bank-accounts [* {:bank-account/type [*]
|
||||
:bank-account/yodlee-account [:yodlee-account/name :yodlee-account/id :yodlee-account/number]
|
||||
:bank-account/plaid-account [:plaid-account/name :db/id :plaid-account/number :plaid-account/balance]
|
||||
:bank-account/intuit-bank-account [:intuit-bank-account/name :intuit-bank-account/external-id :db/id]
|
||||
:bank-account/integration-status [:integration-status/message
|
||||
:db/id
|
||||
:integration-status/last-attempt
|
||||
:integration-status/last-updated
|
||||
{:integration-status/state [:db/ident]}]}
|
||||
]}
|
||||
{:yodlee-provider-account/_client [*]}
|
||||
{:plaid-item/_client [*]}
|
||||
{:client/emails [:db/id :email-contact/email :email-contact/description]}])
|
||||
(->> (dc/q '[:find (pull ?e ?r)
|
||||
:in $ ?r
|
||||
:where [?e :client/name]]
|
||||
(dc/db conn))
|
||||
(dc/db conn)
|
||||
full-read)
|
||||
(map first)
|
||||
(map cleanse)))
|
||||
|
||||
(defn get-minimal []
|
||||
(->> (dc/q '[:find (pull ?e [:client/name :client/code :client/locations :db/id {:client/bank-accounts [{:bank-account/type [:db/ident]} :bank-account/name :bank-account/code :db/id]}])
|
||||
:where [?e :client/name]]
|
||||
(dc/db conn))
|
||||
(map first)
|
||||
(map cleanse)))
|
||||
|
||||
(defn get-by-id [id]
|
||||
(->>
|
||||
(dc/pull (dc/db conn )
|
||||
'[* {:client/bank-accounts [* {:bank-account/type [*]
|
||||
:bank-account/yodlee-account [:yodlee-account/name :yodlee-account/id :yodlee-account/number]
|
||||
:bank-account/intuit-bank-account [:intuit-bank-account/name :intuit-bank-account/external-id :db/id]
|
||||
:bank-account/plaid-account [:plaid-account/name :db/id :plaid-account/number :plaid-account/balance]}]
|
||||
:client/emails [:db/id :email-contact/email :email-contact/description]}
|
||||
{:client/ezcater-locations [{:ezcater-location/caterer [:ezcater-caterer/name :db/id]}
|
||||
:ezcater-location/location
|
||||
:db/id]}
|
||||
{:yodlee-provider-account/_client [*]}
|
||||
{:plaid-item/_client [*]}]
|
||||
full-read
|
||||
id)
|
||||
(cleanse)))
|
||||
|
||||
@@ -105,3 +114,54 @@
|
||||
:text match
|
||||
:exact-match (str/upper-case match)})
|
||||
"client"))
|
||||
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [query (cond-> {:query {:find []
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [db]}
|
||||
|
||||
|
||||
(not (str/blank? (:code args)))
|
||||
(merge-query {:query {:in ['?client-code]
|
||||
:where ['[?e :client/code ?client-code]]}
|
||||
:args [(:code args)]})
|
||||
|
||||
(not (str/blank? (:name-like args)))
|
||||
(merge-query {:query {:in ['?name-like]
|
||||
:where ['[?e :client/name ?name]
|
||||
'[(clojure.string/includes? ?name ?name-like)]]}
|
||||
:args [(:name-like args)]})
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?e ...]]
|
||||
:where []}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||
|
||||
|
||||
(:sort args) (add-sorter-fields {"name" ['[?e :client/name ?sort-name]]}
|
||||
args)
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e] :where ['[?e :client/name ?sort-default]]}}))]
|
||||
(mu/log ::q
|
||||
:query query)
|
||||
(->> query
|
||||
(dc/q)
|
||||
(apply-sort-3 (update args :sort conj {:sort-key "default-2" :asc true}))
|
||||
(apply-pagination args))))
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(let [results (->> (pull-many db full-read
|
||||
ids)
|
||||
(map cleanse))]
|
||||
results))
|
||||
|
||||
|
||||
(defn get-graphql-page [args]
|
||||
(let [db (dc/db conn)
|
||||
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)]
|
||||
|
||||
[(->> (graphql-results ids-to-retrieve db args))
|
||||
matching-count]))
|
||||
|
||||
@@ -9,11 +9,10 @@
|
||||
pull-many
|
||||
visible-clients
|
||||
conn]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[iol-ion.query]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.core :as time]
|
||||
[clojure.set :as set]
|
||||
[clojure.tools.logging :as log]
|
||||
[datomic.client.api :as dc]
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user